View Javadoc
1   /*
2    * Copyright 2012-2025 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.app.pager;
17  
18  import java.io.Serializable;
19  import java.util.List;
20  
21  import org.codelibs.fess.util.ComponentUtil;
22  
23  /**
24   * Pager class for search log pagination and filtering.
25   *
26   * This class provides pagination functionality for various types of search logs
27   * including search logs, click logs, favorite logs, and user information logs.
28   * It also supports different aggregation types for analytics and reporting.
29   */
30  public class SearchLogPager implements Serializable {
31  
32      /** Serial version UID for serialization. */
33      private static final long serialVersionUID = 1L;
34  
35      /** Log type constant for search logs. */
36      public static final String LOG_TYPE_SEARCH = "search";
37  
38      /** Log type constant for hourly search count aggregation. */
39      public static final String LOG_TYPE_SEARCH_COUNT_HOUR = "search_count_hour_agg";
40  
41      /** Log type constant for daily search count aggregation. */
42      public static final String LOG_TYPE_SEARCH_COUNT_DAY = "search_count_day_agg";
43  
44      /** Log type constant for hourly unique user aggregation. */
45      public static final String LOG_TYPE_SEARCH_USER_HOUR = "search_user_hour_agg";
46  
47      /** Log type constant for daily unique user aggregation. */
48      public static final String LOG_TYPE_SEARCH_USER_DAY = "search_user_day_agg";
49  
50      /** Log type constant for hourly average request time aggregation. */
51      public static final String LOG_TYPE_SEARCH_REQTIMEAVG_HOUR = "search_reqtimeavg_hour_agg";
52  
53      /** Log type constant for daily average request time aggregation. */
54      public static final String LOG_TYPE_SEARCH_REQTIMEAVG_DAY = "search_reqtimeavg_day_agg";
55  
56      /** Log type constant for search keyword aggregation. */
57      public static final String LOG_TYPE_SEARCH_KEYWORD = "search_keyword_agg";
58  
59      /** Log type constant for zero-hit search aggregation. */
60      public static final String LOG_TYPE_SEARCH_ZEROHIT = "search_zerohit_agg";
61  
62      /** Log type constant for zero-click search aggregation. */
63      public static final String LOG_TYPE_SEARCH_ZEROCLICK = "search_zeroclick_agg";
64  
65      /** Log type constant for click logs. */
66      public static final String LOG_TYPE_CLICK = "click";
67  
68      /** Log type constant for click count aggregation. */
69      public static final String LOG_TYPE_CLICK_COUNT = "click_count_agg";
70  
71      /** Log type constant for favorite logs. */
72      public static final String LOG_TYPE_FAVORITE = "favorite";
73  
74      /** Log type constant for favorite count aggregation. */
75      public static final String LOG_TYPE_FAVORITE_COUNT = "favorite_count_agg";
76  
77      /** Log type constant for user information logs. */
78      public static final String LOG_TYPE_USERINFO = "user_info";
79  
80      /** Default page size for pagination. */
81      public static final int DEFAULT_PAGE_SIZE = 20;
82  
83      /** Default current page number for pagination. */
84      public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
85  
86      /** Total number of records matching the search criteria. */
87      private int allRecordCount;
88  
89      /** Total number of pages based on record count and page size. */
90      private int allPageCount;
91  
92      /** Flag indicating if a previous page exists. */
93      private boolean existPrePage;
94  
95      /** Flag indicating if a next page exists. */
96      private boolean existNextPage;
97  
98      /** List of page numbers for pagination navigation. */
99      private List<Integer> pageNumberList;
100 
101     /** Number of records to display per page. */
102     private int pageSize;
103 
104     /** Current page number being displayed. */
105     private int currentPageNumber;
106 
107     /** Type of log being displayed (default: search). */
108     public String logType = LOG_TYPE_SEARCH;
109 
110     /** Query ID filter for search logs. */
111     public String queryId;
112 
113     /** User session ID filter for search logs. */
114     public String userSessionId;
115 
116     /** Time range filter for search logs (format: "yyyy-MM-dd HH:mm - yyyy-MM-dd HH:mm"). */
117     public String requestedTimeRange;
118 
119     /** Access type filter for search logs (web, json, gsa, admin, other). */
120     public String accessType;
121 
122     /**
123      * Default constructor for creating a new SearchLogPager instance.
124      */
125     public SearchLogPager() {
126         // Default constructor
127     }
128 
129     /**
130      * Clears all filter criteria and resets pagination to default values.
131      */
132     public void clear() {
133         allRecordCount = 0;
134         allPageCount = 0;
135         existPrePage = false;
136         existNextPage = false;
137         pageSize = getDefaultPageSize();
138         currentPageNumber = getDefaultCurrentPageNumber();
139 
140         queryId = null;
141         userSessionId = null;
142         requestedTimeRange = null;
143         accessType = null;
144         logType = LOG_TYPE_SEARCH;
145 
146     }
147 
148     /**
149      * Gets the default current page number.
150      *
151      * @return The default current page number
152      */
153     protected int getDefaultCurrentPageNumber() {
154         return DEFAULT_CURRENT_PAGE_NUMBER;
155     }
156 
157     /**
158      * Gets the total number of records matching the search criteria.
159      *
160      * @return The total record count
161      */
162     public int getAllRecordCount() {
163         return allRecordCount;
164     }
165 
166     /**
167      * Sets the total number of records matching the search criteria.
168      *
169      * @param allRecordCount The total record count
170      */
171     public void setAllRecordCount(final int allRecordCount) {
172         this.allRecordCount = allRecordCount;
173     }
174 
175     /**
176      * Gets the total number of pages based on record count and page size.
177      *
178      * @return The total page count
179      */
180     public int getAllPageCount() {
181         return allPageCount;
182     }
183 
184     /**
185      * Sets the total number of pages.
186      *
187      * @param allPageCount The total page count
188      */
189     public void setAllPageCount(final int allPageCount) {
190         this.allPageCount = allPageCount;
191     }
192 
193     /**
194      * Checks if a previous page exists.
195      *
196      * @return true if a previous page exists, false otherwise
197      */
198     public boolean isExistPrePage() {
199         return existPrePage;
200     }
201 
202     /**
203      * Sets whether a previous page exists.
204      *
205      * @param existPrePage true if a previous page exists
206      */
207     public void setExistPrePage(final boolean existPrePage) {
208         this.existPrePage = existPrePage;
209     }
210 
211     /**
212      * Checks if a next page exists.
213      *
214      * @return true if a next page exists, false otherwise
215      */
216     public boolean isExistNextPage() {
217         return existNextPage;
218     }
219 
220     /**
221      * Sets whether a next page exists.
222      *
223      * @param existNextPage true if a next page exists
224      */
225     public void setExistNextPage(final boolean existNextPage) {
226         this.existNextPage = existNextPage;
227     }
228 
229     /**
230      * Gets the number of records to display per page.
231      *
232      * @return The page size
233      */
234     public int getPageSize() {
235         if (pageSize <= 0) {
236             pageSize = getDefaultPageSize();
237         }
238         return pageSize;
239     }
240 
241     /**
242      * Sets the number of records to display per page.
243      *
244      * @param pageSize The page size
245      */
246     public void setPageSize(final int pageSize) {
247         this.pageSize = pageSize;
248     }
249 
250     /**
251      * Gets the current page number being displayed.
252      *
253      * @return The current page number
254      */
255     public int getCurrentPageNumber() {
256         if (currentPageNumber <= 0) {
257             currentPageNumber = getDefaultCurrentPageNumber();
258         }
259         return currentPageNumber;
260     }
261 
262     /**
263      * Sets the current page number.
264      *
265      * @param currentPageNumber The current page number
266      */
267     public void setCurrentPageNumber(final int currentPageNumber) {
268         this.currentPageNumber = currentPageNumber;
269     }
270 
271     /**
272      * Gets the list of page numbers for pagination navigation.
273      *
274      * @return The page number list
275      */
276     public List<Integer> getPageNumberList() {
277         return pageNumberList;
278     }
279 
280     /**
281      * Sets the list of page numbers for pagination navigation.
282      *
283      * @param pageNumberList The page number list
284      */
285     public void setPageNumberList(final List<Integer> pageNumberList) {
286         this.pageNumberList = pageNumberList;
287     }
288 
289     /**
290      * Gets the default page size from configuration.
291      *
292      * @return The default page size
293      */
294     protected int getDefaultPageSize() {
295         return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
296     }
297 
298 }