KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > indexing > RangeFieldSearchInput


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.indexing;
6
7 import java.util.Date JavaDoc ;
8 import org.apache.lucene.analysis.Analyzer;
9 import org.apache.lucene.document.DateField;
10 import org.apache.lucene.index.Term ;
11 import org.apache.lucene.search.* ;
12 /**
13  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
14  * @since Sep 12, 2004
15  * @version $Id: RangeFieldSearchInput.java,v 1.1 2004/10/14 23:27:57 tuan08 Exp $
16  */

17 public class RangeFieldSearchInput implements SearchInput {
18   
19   private String JavaDoc field_ ;
20   private String JavaDoc lowerTerm_ ;
21   private String JavaDoc upperTerm_ ;
22   private boolean inclusive_ = true ;
23   
24   public RangeFieldSearchInput(String JavaDoc field, Date JavaDoc lowerTerm, Date JavaDoc upperTerm) {
25     field_ = field ;
26     if(lowerTerm != null)
27       lowerTerm_ = DateField.dateToString(lowerTerm) ;
28     if(upperTerm != null)
29       upperTerm_ = DateField.dateToString(upperTerm) ;
30   }
31   
32   public RangeFieldSearchInput(String JavaDoc field, String JavaDoc lowerTerm, String JavaDoc upperTerm) {
33     field_ = field ;
34     lowerTerm_ = lowerTerm ;
35     upperTerm_ = upperTerm ;
36   }
37   
38   public String JavaDoc getField() { return field_ ; }
39   
40   public void setInclusive(boolean b) { inclusive_ = b ; }
41   
42   public boolean hasTerm() {
43     return (upperTerm_ != null && upperTerm_.length() > 0) || lowerTerm_ != null && lowerTerm_.length() > 0;
44   }
45   
46   public Query getQuery(Analyzer analyzer) throws Exception JavaDoc {
47     Term lower = null ;
48     if(lowerTerm_ != null)lower = new Term(field_, lowerTerm_) ;
49     Term upper = null ;
50     if(upperTerm_ != null) upper = new Term(field_, upperTerm_) ;
51     return new RangeQuery(lower, upper, inclusive_) ;
52   }
53 }
Popular Tags