lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Deb Lucene <deb.luc...@gmail.com>
Subject Multi field search with values
Date Wed, 14 Mar 2012 15:32:39 GMT
Hi Group,

I am working on a Lucene search solution for multiple fields. So far, if
the fields are of string type I am having no difficulties in retrieving
using the MultiFieldQueryParser. For example, my indexing and searching
logic look like this -

indexing
- I am indexing a corpus on the content of the documents and some keywords
of the documents.

**********************************************
String doc = getText(id) ;
List<String> keywords = getKeywords(doc);
 document.add(new Field("content", doc, Field.Store.NO,Field.Index.ANALYZED,
Field.TermVector.YES));
for ( String keyword : keywords )
 {
    document.add(new Field("keyword", keyword, Field.Store.NO,
Field.Index.ANALYZED, Field.TermVector.YES));
 }
*********************************************
I am searching over the indexes using some query text and predefined
keywords
searching :
********************************************
String queryText = getQuery();
String keyword = getKeyword();
 BooleanClause.Occur[] flags =
{BooleanClause.Occur.SHOULD,BooleanClause.Occur.SHOULD};
 Query query = MultiFieldQueryParser.parse(Version.LUCENE_33, new String[]
{queryText, keyword},
                 new String[]{"content","keywords"}, flags, stAnalyzer);
[stAnalyzer is the standard analyzer]

 TopDocs hits = isearcher.search(query, 20);

********************************************

This code is working fine. But now suppose I add one more field (a
"threshold" set on some prior calculation) which is of numeric type.
NumericField field = new NumericField("threshold") ;
document.add(field.setDoubleValue(threhold));

Now can I search over multiple fields using the "string" type (i.e. content
and keywords) with the "double" type (i.e. the threshold)?
I am particularly looking for a query such as -
query - "some content" and "some keywords" and threshold > 0.5.

I surmise I need to use the "numeric field search" technique but not sure
how to add the functionality in MultiFieldQueryParser.

Thanks in advance,
--d

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message