View Javadoc
1   /*
2    * Copyright 2012-2021 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.web.admin.searchlist;
17  
18  import static org.codelibs.core.stream.StreamUtil.stream;
19  
20  import java.util.HashMap;
21  import java.util.Locale;
22  import java.util.Map;
23  
24  import javax.validation.constraints.Size;
25  
26  import org.codelibs.core.lang.StringUtil;
27  import org.codelibs.fess.entity.FacetInfo;
28  import org.codelibs.fess.entity.GeoInfo;
29  import org.codelibs.fess.entity.HighlightInfo;
30  import org.codelibs.fess.entity.SearchRequestParams;
31  import org.codelibs.fess.mylasta.direction.FessConfig;
32  import org.codelibs.fess.util.ComponentUtil;
33  import org.lastaflute.web.util.LaRequestUtil;
34  import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
35  
36  /**
37   * @author shinsuke
38   * @author Keiichi Watanabe
39   */
40  public class ListForm extends SearchRequestParams {
41  
42      @Size(max = 1000)
43      public String q;
44  
45      public String sort;
46  
47      @ValidateTypeFailure
48      public Integer start;
49  
50      @ValidateTypeFailure
51      public Integer pn;
52  
53      @ValidateTypeFailure
54      public Integer num;
55  
56      public String[] lang;
57  
58      public Map<String, String[]> fields = new HashMap<>();
59  
60      public Map<String, String[]> as = new HashMap<>();
61  
62      public String[] ex_q;
63  
64      public String sdh;
65  
66      @Override
67      public String getQuery() {
68          return q;
69      }
70  
71      @Override
72      public String[] getExtraQueries() {
73          return stream(ex_q).get(stream -> stream.filter(StringUtil::isNotBlank).distinct().toArray(n -> new String[n]));
74      }
75  
76      @Override
77      public Map<String, String[]> getFields() {
78          return fields;
79      }
80  
81      @Override
82      public Map<String, String[]> getConditions() {
83          return as;
84      }
85  
86      @Override
87      public int getStartPosition() {
88          if (start == null) {
89              start = ComponentUtil.getFessConfig().getPagingSearchPageStartAsInteger();
90          }
91          return start;
92      }
93  
94      @Override
95      public int getPageSize() {
96          final FessConfig fessConfig = ComponentUtil.getFessConfig();
97          if (num == null) {
98              num = fessConfig.getPagingSearchPageSizeAsInteger();
99          }
100         if (num > fessConfig.getPagingSearchPageMaxSizeAsInteger().intValue() || num <= 0) {
101             num = fessConfig.getPagingSearchPageMaxSizeAsInteger();
102         }
103         return num;
104     }
105 
106     @Override
107     public String[] getLanguages() {
108         return stream(lang).get(stream -> stream.filter(StringUtil::isNotBlank).distinct().toArray(n -> new String[n]));
109     }
110 
111     @Override
112     public GeoInfo getGeoInfo() {
113         return null;
114     }
115 
116     @Override
117     public FacetInfo getFacetInfo() {
118         return null;
119     }
120 
121     @Override
122     public HighlightInfo getHighlightInfo() {
123         return new HighlightInfo();
124     }
125 
126     @Override
127     public String getSort() {
128         return sort;
129     }
130 
131     public void initialize() {
132         final FessConfig fessConfig = ComponentUtil.getFessConfig();
133         if (start == null) {
134             start = fessConfig.getPagingSearchPageStartAsInteger();
135         }
136         if (num == null) {
137             num = fessConfig.getPagingSearchPageSizeAsInteger();
138         } else if (num > fessConfig.getPagingSearchPageMaxSizeAsInteger().intValue()) {
139             num = fessConfig.getPagingSearchPageMaxSizeAsInteger();
140         }
141     }
142 
143     @Override
144     public Object getAttribute(final String name) {
145         return LaRequestUtil.getRequest().getAttribute(name);
146     }
147 
148     @Override
149     public Locale getLocale() {
150         return ComponentUtil.getRequestManager().getUserLocale();
151     }
152 
153     @Override
154     public SearchRequestType getType() {
155         return SearchRequestType.ADMIN_SEARCH;
156     }
157 
158     @Override
159     public String getSimilarDocHash() {
160         return sdh;
161     }
162 
163     @Override
164     public String getTrackTotalHits() {
165         final String value = ComponentUtil.getFessConfig().getPageSearchlistTrackTotalHits();
166         if (StringUtil.isNotBlank(value)) {
167             return value;
168         }
169         return null;
170     }
171 }