View Javadoc
1   /*
2    * Copyright (C) 2003-2008 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.wcm.search;
18  
19  import java.util.Calendar;
20  
21  import org.exoplatform.services.wcm.utils.AbstractQueryBuilder.COMPARISON_TYPE;
22  
23  /**
24   * Created by The eXo Platform SAS
25   * Author : Hoa Pham
26   * hoa.pham@exoplatform.com
27   * Oct 7, 2008
28   */
29  /*
30   * This is query criteria for SiteSearch service. Base on search criteria, SiteSearch service
31   * can easy create query statement to search.
32   * */
33  public class QueryCriteria {
34  
35    /** The Constant ALL_PROPERTY_SCOPE. */
36    public static final String ALL_PROPERTY_SCOPE = ".";
37  
38    /** The site name. */
39    private String siteName;
40  
41    /** The categories. */
42    private String[] categoryUUIDs = null;
43  
44    /** The tags. */
45    private String[] tagUUIDs = null;
46  
47    /** The start publication date. */
48    private DatetimeRange startPublicationDateRange = null;
49  
50    /** The end publication date. */
51    private DatetimeRange endPublicationDateRange = null;
52  
53    /** The authors. */
54    private String[] authors = null;
55  
56    /** The content types. */
57    private String[] contentTypes = null;  
58    
59    /** The mime types. */
60    private String[] mimeTypes = null;
61    
62    /** The node types. */
63    private String[] nodeTypes = null;
64  
65    /** The created date. */
66    private DatetimeRange createdDateRange = null;
67  
68    /** The last modified date. */
69    private DatetimeRange lastModifiedDateRange = null;
70  
71    /** The search webpage. */
72    private boolean searchWebpage = true;
73  
74    /** The search document. */
75    private boolean searchDocument = true;
76  
77    /** The keyword. */
78    private String keyword = null;
79  
80    /** The search web content. */
81    private boolean searchWebContent = true;
82  
83    /** The fulltext search. */
84    private boolean fulltextSearch = true;
85    
86    /** The fuzzy search. */
87    private boolean fuzzySearch = false;
88  
89    /** The is live mode. */
90    private boolean isLiveMode = true;
91  
92    /** The starting offset */
93    private long offset = -1;
94    
95    /** The search limit */
96    private long limit = -1;
97    
98    /** Sort by value */
99    private String sortBy_ = null;
100   
101   /** order by */
102   private String orderBy_ = null;
103   
104   private String searchPath_ = null;
105 
106   /** Pagination mode :
107    * - none : no pagination
108    * - more : twitter like pagination with "more" link
109    * - pagination : pagination mode with page number and total size */
110   private String pageMode = SiteSearchService.PAGE_MODE_NONE;
111 
112   public String getPageMode() {
113     return pageMode;
114   }
115 
116   public void setPageMode(String pageMode) {
117     this.pageMode = pageMode;
118   }
119 
120   public long getOffset() { return offset; }
121 
122   public void setOffset(long offset) { this.offset = offset; }
123   
124   public long getLimit() { return limit; }
125   
126   public void setLimit(long value) { this.limit = value; }
127   
128   public String getSortBy() { return sortBy_; }
129   
130   public void setSortBy(String value) { sortBy_ = value; }
131   
132   public String getOrderBy() { return orderBy_; }
133   
134   public void setOrderBy(String value) { orderBy_ = value; }
135   
136   public String getSearchPath() { return searchPath_; }
137   
138   public void setSearchPath(String value) { searchPath_ = value; }
139   
140   /**
141    * Checks if is live mode.
142    *
143    * @return true, if is live mode
144    */
145   public boolean isLiveMode() {
146     return isLiveMode;
147   }
148 
149   /**
150    * Sets the live mode.
151    *
152    * @param isLiveMode the new live mode
153    */
154   public void setLiveMode(boolean isLiveMode) {
155     this.isLiveMode = isLiveMode;
156   }
157 
158   /** The query metadatas. */
159   private QueryProperty[] queryMetadatas = null;
160 
161   /** The fulltext search property. */
162   private String[]            fulltextSearchProperty = new String[] { ALL_PROPERTY_SCOPE };
163 
164   /** The date range selected. */
165   private DATE_RANGE_SELECTED dateRangeSelected = null;
166 
167   /**
168    * Gets the site name.
169    *
170    * @return the site name
171    */
172   public String getSiteName() { return siteName; }
173 
174   /**
175    * Sets the site name.
176    *
177    * @param siteName the new site name
178    */
179   public void setSiteName(String siteName) { this.siteName = siteName; }
180 
181 
182   /**
183    * Gets the authors.
184    *
185    * @return the authors
186    */
187   public String[] getAuthors() { return authors; }
188 
189   /**
190    * Sets the authors.
191    *
192    * @param authors the new authors
193    */
194   public void setAuthors(String[] authors) { this.authors = authors; }
195 
196   /**
197    * Gets the content types.
198    *
199    * @return the content types
200    */
201   public String[] getContentTypes() { return contentTypes; }
202   
203   
204 
205   /**
206    * Sets the content types.
207    *
208    * @param contentTypes the new content types
209    */
210   public void setContentTypes(String[] contentTypes) { this.contentTypes = contentTypes; }
211   
212   /**
213    * Gets the mime types.
214    *
215    * @return the mime types
216    */
217   public String[] getMimeTypes() { return mimeTypes; }
218 
219   /**
220    * Sets the mime types.
221    *
222    * @param mimeTypes the new mime types
223    */
224   public void setMimeTypes(String[] mimeTypes) { this.mimeTypes = mimeTypes; }
225   
226   
227   public String[] getNodeTypes() {
228     return nodeTypes;
229   }
230   
231   public void setNodeTypes(String[] nodeTypes) {
232     this.nodeTypes = nodeTypes;
233   }
234 
235   /**
236    * Gets the start publication date range.
237    *
238    * @return the start publication date range
239    */
240   public DatetimeRange getStartPublicationDateRange() {
241     return startPublicationDateRange;
242   }
243 
244   /**
245    * Sets the start publication date range.
246    *
247    * @param startPublicationDateRange the new start publication date range
248    */
249   public void setStartPublicationDateRange(DatetimeRange startPublicationDateRange) {
250     this.startPublicationDateRange = startPublicationDateRange;
251   }
252 
253   /**
254    * Gets the end publication date range.
255    *
256    * @return the end publication date range
257    */
258   public DatetimeRange getEndPublicationDateRange() {
259     return endPublicationDateRange;
260   }
261 
262   /**
263    * Sets the end publication date range.
264    *
265    * @param endPublicationDateRange the new end publication date range
266    */
267   public void setEndPublicationDateRange(DatetimeRange endPublicationDateRange) {
268     this.endPublicationDateRange = endPublicationDateRange;
269   }
270 
271   /**
272    * Gets the created date range.
273    *
274    * @return the created date range
275    */
276   public DatetimeRange getCreatedDateRange() {
277     return createdDateRange;
278   }
279 
280   /**
281    * Sets the created date range.
282    *
283    * @param createdDateRange the new created date range
284    */
285   public void setCreatedDateRange(DatetimeRange createdDateRange) {
286     this.createdDateRange = createdDateRange;
287   }
288 
289   /**
290    * Gets the last modified date range.
291    *
292    * @return the last modified date range
293    */
294   public DatetimeRange getLastModifiedDateRange() {
295     return lastModifiedDateRange;
296   }
297 
298   /**
299    * Sets the last modified date range.
300    *
301    * @param lastModifiedDateRange the new last modified date range
302    */
303   public void setLastModifiedDateRange(DatetimeRange lastModifiedDateRange) {
304     this.lastModifiedDateRange = lastModifiedDateRange;
305   }
306 
307   /**
308    * Checks if is fulltext search.
309    *
310    * @return true, if is fulltext search
311    */
312   public boolean isFulltextSearch() {
313     return fulltextSearch;
314   }
315   
316   /**
317    * Checks if is fuzzy search.
318    *
319    * @return true, if is fuzzy search
320    */
321   public boolean isFuzzySearch() {
322     return fuzzySearch;
323   }
324 
325 
326   /**
327    * Sets the fulltext search.
328    *
329    * @param fulltextSearch the new fulltext search
330    */
331   public void setFulltextSearch(boolean fulltextSearch) {
332     this.fulltextSearch = fulltextSearch;
333   }
334   
335   /**
336    * Sets the fuzzy search.
337    *
338    * @param fuzzySearch the new fuzzy search
339    */
340   public void setFuzzySearch(boolean fuzzySearch) {
341     this.fuzzySearch = fuzzySearch;
342   }
343 
344   /**
345    * Gets the keyword.
346    *
347    * @return the keyword
348    */
349   public String getKeyword() { return this.keyword; }
350 
351   /**
352    * Sets the keyword.
353    *
354    * @param s the new keyword
355    */
356   public void setKeyword(String s) { this.keyword = s; }
357 
358   /**
359    * Checks if is search webpage.
360    *
361    * @return true, if is search webpage
362    */
363   public boolean isSearchWebpage() { return searchWebpage;}
364 
365   /**
366    * Sets the search webpage.
367    *
368    * @param searchWebpage the new search webpage
369    */
370   public void setSearchWebpage(boolean searchWebpage) {
371     this.searchWebpage = searchWebpage;
372   }
373 
374   /**
375    * Checks if is search document.
376    *
377    * @return true, if is search document
378    */
379   public boolean isSearchDocument() { return searchDocument;}
380 
381   /**
382    * Sets the search document.
383    *
384    * @param searchDocument the new search document
385    */
386   public void setSearchDocument(boolean searchDocument) {
387     this.searchDocument = searchDocument;
388   }
389 
390   /**
391    * Checks if is search web content.
392    *
393    * @return true, if is search web content
394    */
395   public boolean isSearchWebContent() {
396     return searchWebContent;
397   }
398 
399   /**
400    * Sets the search web content.
401    *
402    * @param searchWebContent the new search web content
403    */
404   public void setSearchWebContent(boolean searchWebContent) {
405     this.searchWebContent = searchWebContent;
406   }
407 
408   /**
409    * The Class DatetimeRange.
410    */
411   public static class DatetimeRange {
412 
413     /** The from date. */
414     private Calendar fromDate;
415 
416     /** The to date. */
417     private Calendar toDate;
418 
419     /**
420      * Instantiates a new datetime range.
421      *
422      * @param fromDate the from date
423      * @param toDate the to date
424      */
425     public DatetimeRange(Calendar fromDate, Calendar toDate) {
426       this.fromDate = fromDate;
427       this.toDate = toDate;
428     }
429 
430     /**
431      * Gets the from date.
432      *
433      * @return the from date
434      */
435     public Calendar getFromDate() {
436       return fromDate;
437     }
438 
439     /**
440      * Sets the from date.
441      *
442      * @param fromDate the new from date
443      */
444     public void setFromDate(Calendar fromDate) {
445       this.fromDate = fromDate;
446     }
447 
448     /**
449      * Gets the to date.
450      *
451      * @return the to date
452      */
453     public Calendar getToDate() {
454       return toDate;
455     }
456 
457     /**
458      * Sets the to date.
459      *
460      * @param toDate the new to date
461      */
462     public void setToDate(Calendar toDate) {
463       this.toDate = toDate;
464     }
465   }
466 
467   /**
468    * The Enum DATE_RANGE_SELECTED.
469    */
470   public enum DATE_RANGE_SELECTED {
471     /** The CREATED. */
472     CREATED, /** The MODIFIDED. */
473     MODIFIDED, /** The STAR t_ publication. */
474     START_PUBLICATION, /** The EN d_ publication. */
475     END_PUBLICATION
476   }
477 
478   /**
479    * Gets the date range selected.
480    *
481    * @return the date range selected
482    */
483   public DATE_RANGE_SELECTED getDateRangeSelected() {
484     return dateRangeSelected;
485   }
486 
487   /**
488    * Sets the date range selected.
489    *
490    * @param dateRangeSelected the new date range selected
491    */
492   public void setDateRangeSelected(DATE_RANGE_SELECTED dateRangeSelected) {
493     this.dateRangeSelected = dateRangeSelected;
494   }
495 
496   /**
497    * Gets the category uui ds.
498    *
499    * @return the category uui ds
500    */
501   public String[] getCategoryUUIDs() {
502     return categoryUUIDs;
503   }
504 
505   /**
506    * Sets the category uui ds.
507    *
508    * @param categoryUUIDs the new category uui ds
509    */
510   public void setCategoryUUIDs(String[] categoryUUIDs) {
511     this.categoryUUIDs = categoryUUIDs;
512   }
513 
514   /**
515    * Gets the tag uui ds.
516    *
517    * @return the tag uui ds
518    */
519   public String[] getTagUUIDs() {
520     return tagUUIDs;
521   }
522 
523   /**
524    * Sets the tag uui ds.
525    *
526    * @param tagUUIDs the new tag uui ds
527    */
528   public void setTagUUIDs(String[] tagUUIDs) {
529     this.tagUUIDs = tagUUIDs;
530   };
531 
532 
533   /**
534    * The Class QueryProperty.
535    */
536   public class QueryProperty {
537 
538     /** The name. */
539     private String name;
540 
541     /** The value. */
542     private String value;
543     
544     /** The comparison type */
545     private COMPARISON_TYPE comparisonType;
546 
547     /**
548      * Gets the name.
549      *
550      * @return the name
551      */
552     public String getName() {
553       return name;
554     }
555 
556     /**
557      * Sets the name.
558      *
559      * @param name the new name
560      */
561     public void setName(String name) {
562       this.name = name;
563     }
564 
565     /**
566      * Gets the value.
567      *
568      * @return the value
569      */
570     public String getValue() {
571       return value;
572     }
573 
574     /**
575      * Sets the value.
576      *
577      * @param value the new value
578      */
579     public void setValue(String value) {
580       this.value = value;
581     }
582 
583     /**
584      * @param comparisonType the comparisonType to set
585      */
586     public void setComparisonType(COMPARISON_TYPE comparisonType) {
587       this.comparisonType = comparisonType;
588     }
589 
590     /**
591      * @return the comparisonType
592      */
593     public COMPARISON_TYPE getComparisonType() {
594       if (comparisonType == null) {
595         return COMPARISON_TYPE.LIKE;
596       }
597       return comparisonType;
598     }
599   }
600 
601 
602   /**
603    * Gets the query metadatas.
604    *
605    * @return the query metadatas
606    */
607   public QueryProperty[] getQueryMetadatas() {
608     return queryMetadatas;
609   }
610 
611   /**
612    * Sets the query metadatas.
613    *
614    * @param queryMetadatas the new query metadatas
615    */
616   public void setQueryMetadatas(QueryProperty[] queryMetadatas) {
617     this.queryMetadatas = queryMetadatas;
618   }
619 
620   /**
621    * Gets the fulltext search property.
622    *
623    * @return the fulltext search property
624    */
625   public String[] getFulltextSearchProperty() {
626     return fulltextSearchProperty;
627   }
628 
629   /**
630    * Sets the fulltext search property.
631    *
632    * @param fulltextSearchProperty the new fulltext search property
633    */
634   public void setFulltextSearchProperty(String[] fulltextSearchProperty) {
635     this.fulltextSearchProperty = fulltextSearchProperty;
636   }
637 }