lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: do a simple search
Date Wed, 05 Jan 2005 09:31:26 GMT

On Jan 5, 2005, at 3:41 AM, Stephane.Giner@apis-ca.fr wrote:
> I would like to search a word in differents fields of a document with 
> an
> OR operator.
>
> My fields are "id", "shortDesc" and "longDesc".
> In java I want to search a word simultanly in "shortDesc" and 
> "longDesc"
> field.
>
> for example:
>
>         doc1:   id:1
>                         shortDesc: a foo desc
>                         longDesc: a doc long desc
>
>         doc2:   id:2
>                 shortDesc:a doc short desc
>                 longDesc:a foo long desc
>
>         doc3:   id:3
>                 shortDesc:another short desc
>                 longDesc:another long desc
>
> if the search word is "foo" i want to retreive doc1 and doc3.

You meant doc1 and doc2.

> in my program, fields are stored in fieldName list.
> associated values are stored in fieldValue.


What's the question?  The code you show below, at first glance, looks 
reasonable, or at least close.  What is the value of query.toString()

	Erik


>         private static Hits search(List fieldName, List fieldValue) {
>                 Hits hits = null;
>
>                 int fieldNameSize  = fieldName.size();
>                 int fieldValueSize = fieldValue.size();
>                 if (fieldNameSize != fieldValueSize) {
>                         return null;
>                 }
>
>                 IndexSearcher searcher = getSearcher();
>                 if (searcher != null) {
>                         BooleanQuery query = new BooleanQuery();
>                         //populate the query with all terms
>                         for (int i=0; i<fieldNameSize; i++) {
>                                 String currentFieldName  = (String)
> fieldName.get(i);
>                                 String currentFieldValue = (String)
> fieldValue.get(i);
>
>                                 StringTokenizer tokenizer = new
> StringTokenizer(currentFieldValue);
>                                 while (tokenizer.hasMoreTokens()) {
>                                         String currentToken =
> tokenizer.nextToken();
>                                         Term currentTerm = new
> Term(currentFieldName,currentToken);
>                                         TermQuery termQuery = new
> TermQuery(currentTerm);
>
>                                         
> query.add(termQuery,false,false);
>                                 }
>                         }
>
>                         //do the search
>                         try {
>                                 //System.out.println("IndexManager 
> query =
> " + query.toString());
>                                 hits = searcher.search(query);
>                         }
>                         catch (IOException ioe) {
>  LogManager.log(LogManager.LOG_ERROR,"Cannot search in index.",ioe);
>                         }
>                         finally {
>                                 try {
>                                         searcher.close();
>                                 }
>                                 catch (IOException ioe) {
>  LogManager.log(LogManager.LOG_WARNING,"Cannot close searcher in search
> method.",ioe);
>                                 }
>                         }
>                 }
>
>                 return hits;
>         }


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Mime
View raw message