KickJava   Java API By Example, From Geeks To Geeks.

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


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.* ;
8 import org.apache.lucene.analysis.Analyzer;
9 import org.apache.lucene.queryParser.QueryParser ;
10 import org.apache.lucene.search.* ;
11 /**
12  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
13  * @since Sep 12, 2004
14  * @version $Id: MultipleFieldSearchInput.java,v 1.2 2004/09/18 19:20:55 tuan08 Exp $
15  */

16 public class MultipleFieldSearchInput implements SearchInput {
17   private List field_ ;
18   private String JavaDoc term_ ;
19   private boolean matchAllFields_ = false ;
20   
21   public MultipleFieldSearchInput(List field) {
22     field_ = field ;
23   }
24   
25   public List getField() { return field_ ; }
26   public void setField(List field) { field_ = field ; }
27   
28   public String JavaDoc getTerm() { return term_ ; }
29   public void setTerm(String JavaDoc term) { term_ = term ; }
30   
31   public boolean isMatchAllFields() { return matchAllFields_ ; }
32   public void setMatchAllFields(boolean b) { matchAllFields_ = b ; }
33   
34   public boolean hasTerm() {
35     return term_ != null && term_.length() > 0;
36   }
37   
38   
39   public Query getQuery(Analyzer analyzer) throws Exception JavaDoc {
40     BooleanQuery bquery = new BooleanQuery() ;
41     for(int i = 0; i < field_.size(); i++) {
42       String JavaDoc field = (String JavaDoc)field_.get(i) ;
43       Query fieldquery = QueryParser.parse(term_ , field , analyzer) ;
44       bquery.add(fieldquery, matchAllFields_, false) ;
45     }
46     return bquery ;
47   }
48 }
Popular Tags