001
014
015 package com.liferay.portal.search.lucene;
016
017 import com.liferay.portal.kernel.search.BaseBooleanQueryImpl;
018 import com.liferay.portal.kernel.search.BooleanClause;
019 import com.liferay.portal.kernel.search.BooleanClauseOccur;
020 import com.liferay.portal.kernel.search.BooleanClauseOccurImpl;
021 import com.liferay.portal.kernel.search.ParseException;
022 import com.liferay.portal.kernel.search.Query;
023 import com.liferay.portal.kernel.search.QueryTranslatorUtil;
024
025 import java.util.ArrayList;
026 import java.util.List;
027
028
032 public class BooleanQueryImpl extends BaseBooleanQueryImpl {
033
034 public BooleanQueryImpl() {
035 _booleanQuery = new org.apache.lucene.search.BooleanQuery();
036 }
037
038 @Override
039 public void add(Query query, BooleanClauseOccur booleanClauseOccur)
040 throws ParseException {
041
042 _booleanQuery.add(
043 (org.apache.lucene.search.Query)QueryTranslatorUtil.translate(
044 query),
045 BooleanClauseOccurTranslator.translate(booleanClauseOccur));
046 }
047
048 @Override
049 public void add(Query query, String occur) throws ParseException {
050 BooleanClauseOccur booleanClauseOccur = new BooleanClauseOccurImpl(
051 occur);
052
053 add(query, booleanClauseOccur);
054 }
055
056 @Override
057 public void addExactTerm(String field, boolean value) {
058 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
059 }
060
061 @Override
062 public void addExactTerm(String field, Boolean value) {
063 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
064 }
065
066 @Override
067 public void addExactTerm(String field, double value) {
068 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
069 }
070
071 @Override
072 public void addExactTerm(String field, Double value) {
073 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
074 }
075
076 @Override
077 public void addExactTerm(String field, int value) {
078 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
079 }
080
081 @Override
082 public void addExactTerm(String field, Integer value) {
083 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
084 }
085
086 @Override
087 public void addExactTerm(String field, long value) {
088 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
089 }
090
091 @Override
092 public void addExactTerm(String field, Long value) {
093 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
094 }
095
096 @Override
097 public void addExactTerm(String field, short value) {
098 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
099 }
100
101 @Override
102 public void addExactTerm(String field, Short value) {
103 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
104 }
105
106 @Override
107 public void addExactTerm(String field, String value) {
108 LuceneHelperUtil.addExactTerm(_booleanQuery, field, value);
109 }
110
111 @Override
112 public void addNumericRangeTerm(
113 String field, int startValue, int endValue) {
114
115 LuceneHelperUtil.addNumericRangeTerm(
116 _booleanQuery, field, startValue, endValue);
117 }
118
119 @Override
120 public void addNumericRangeTerm(
121 String field, Integer startValue, Integer endValue) {
122
123 LuceneHelperUtil.addNumericRangeTerm(
124 _booleanQuery, field, startValue, endValue);
125 }
126
127 @Override
128 public void addNumericRangeTerm(
129 String field, long startValue, long endValue) {
130
131 LuceneHelperUtil.addNumericRangeTerm(
132 _booleanQuery, field, startValue, endValue);
133 }
134
135 @Override
136 public void addNumericRangeTerm(
137 String field, Long startValue, Long endValue) {
138
139 LuceneHelperUtil.addNumericRangeTerm(
140 _booleanQuery, field, startValue, endValue);
141 }
142
143 @Override
144 public void addNumericRangeTerm(
145 String field, short startValue, short endValue) {
146
147 LuceneHelperUtil.addNumericRangeTerm(
148 _booleanQuery, field, startValue, endValue);
149 }
150
151 @Override
152 public void addNumericRangeTerm(
153 String field, Short startValue, Short endValue) {
154
155 LuceneHelperUtil.addNumericRangeTerm(
156 _booleanQuery, field, startValue, endValue);
157 }
158
159 @Override
160 public void addRangeTerm(String field, int startValue, int endValue) {
161 LuceneHelperUtil.addRangeTerm(
162 _booleanQuery, field, startValue, endValue);
163 }
164
165 @Override
166 public void addRangeTerm(
167 String field, Integer startValue, Integer endValue) {
168
169 LuceneHelperUtil.addRangeTerm(
170 _booleanQuery, field, startValue, endValue);
171 }
172
173 @Override
174 public void addRangeTerm(String field, long startValue, long endValue) {
175 LuceneHelperUtil.addRangeTerm(
176 _booleanQuery, field, startValue, endValue);
177 }
178
179 @Override
180 public void addRangeTerm(String field, Long startValue, Long endValue) {
181 LuceneHelperUtil.addRangeTerm(
182 _booleanQuery, field, startValue, endValue);
183 }
184
185 @Override
186 public void addRangeTerm(String field, short startValue, short endValue) {
187 LuceneHelperUtil.addRangeTerm(
188 _booleanQuery, field, startValue, endValue);
189 }
190
191 @Override
192 public void addRangeTerm(String field, Short startValue, Short endValue) {
193 LuceneHelperUtil.addRangeTerm(
194 _booleanQuery, field, startValue, endValue);
195 }
196
197 @Override
198 public void addRangeTerm(String field, String startValue, String endValue) {
199 LuceneHelperUtil.addRangeTerm(
200 _booleanQuery, field, startValue, endValue);
201 }
202
203 @Override
204 public void addRequiredTerm(String field, boolean value) {
205 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
206 }
207
208 @Override
209 public void addRequiredTerm(String field, Boolean value) {
210 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
211 }
212
213 @Override
214 public void addRequiredTerm(String field, double value) {
215 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
216 }
217
218 @Override
219 public void addRequiredTerm(String field, Double value) {
220 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
221 }
222
223 @Override
224 public void addRequiredTerm(String field, int value) {
225 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
226 }
227
228 @Override
229 public void addRequiredTerm(String field, Integer value) {
230 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
231 }
232
233 @Override
234 public void addRequiredTerm(String field, long value) {
235 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
236 }
237
238 @Override
239 public void addRequiredTerm(String field, Long value) {
240 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
241 }
242
243 @Override
244 public void addRequiredTerm(String field, short value) {
245 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
246 }
247
248 @Override
249 public void addRequiredTerm(String field, Short value) {
250 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
251 }
252
253 @Override
254 public void addRequiredTerm(String field, String value) {
255 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value);
256 }
257
258 @Override
259 public void addRequiredTerm(String field, String value, boolean like) {
260 LuceneHelperUtil.addRequiredTerm(_booleanQuery, field, value, like);
261 }
262
263 @Override
264 public void addTerm(String field, long value) {
265 LuceneHelperUtil.addTerm(_booleanQuery, field, value);
266 }
267
268 @Override
269 public void addTerm(String field, String value) {
270 LuceneHelperUtil.addTerm(_booleanQuery, field, value);
271 }
272
273 @Override
274 public void addTerm(String field, String value, boolean like) {
275 LuceneHelperUtil.addTerm(_booleanQuery, field, value, like);
276 }
277
278 @Override
279 public void addTerm(
280 String field, String value, boolean like,
281 BooleanClauseOccur booleanClauseOccur) {
282
283 LuceneHelperUtil.addTerm(
284 _booleanQuery, field, value, like, booleanClauseOccur);
285 }
286
287 @Override
288 public List<BooleanClause> clauses() {
289 List<org.apache.lucene.search.BooleanClause> luceneBooleanClauses =
290 _booleanQuery.clauses();
291
292 List<BooleanClause> booleanClauses = new ArrayList<BooleanClause>(
293 luceneBooleanClauses.size());
294
295 for (int i = 0; i < luceneBooleanClauses.size(); i++) {
296 BooleanClause booleanClause = new BooleanClauseImpl(
297 luceneBooleanClauses.get(i));
298
299 booleanClauses.add(booleanClause);
300 }
301
302 return booleanClauses;
303 }
304
305 public org.apache.lucene.search.BooleanQuery getBooleanQuery() {
306 return _booleanQuery;
307 }
308
309 @Override
310 public Object getWrappedQuery() {
311 return getBooleanQuery();
312 }
313
314 @Override
315 public boolean hasClauses() {
316 return !clauses().isEmpty();
317 }
318
319 @Override
320 public String toString() {
321 return _booleanQuery.toString();
322 }
323
324 private org.apache.lucene.search.BooleanQuery _booleanQuery;
325
326 }