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