How to use multifieldquery and filters in Lucene.net

Posted by Khotu Nam on Stack Overflow See other posts from Stack Overflow or by Khotu Nam
Published on 2010-02-02T17:31:07Z Indexed on 2010/06/13 16:02 UTC
Read the original article Hit count: 288

Filed under:
|

I want to perform a multi field search on a lucene.net index but filter the results based on one of the fields. Here's what I'm currently doing:

To index the fields the definitions are:

doc.Add(new Field("id", id.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.Add(new Field("title", title, Field.Store.NO, Field.Index.TOKENIZED));
doc.Add(new Field("summary", summary, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.YES));
doc.Add(new Field("description", description, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.YES));
doc.Add(new Field("distribution", distribution, Field.Store.NO, Field.Index.UN_TOKENIZED));

When I perform the search I do the following:

MultiFieldQueryParser parser = new MultiFieldQueryParser(new string[]{"title", "summary", "description"}, analyzer);
parser.SetDefaultOperator(QueryParser.Operator.AND);
Query query = parser.Parse(text);

BooleanQuery bq = new BooleanQuery();
TermQuery tq = new TermQuery(new Term("distribution", distribution));
bq.Add(tq, BooleanClause.Occur.MUST);
Filter filter = new QueryFilter(bq);

Hits hits = searcher.Search(query, filter);

However, the result is always 0 hits.

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about filter

Related posts about lucene.net