0

I am doing a free text search on my Lucene index using MultiFieldQueryParser on 2 fields, this works fine. Below is how I am building the search query:

var searchParser = new MultiFieldQueryParser(_currentLuceneVersion, new[] { _titleField, _bodyField }, _standardAnalyzer);
Query searchQuery = searchParser.Parse(searchText);

I have now added a new field, which is a boolean (1 or 0 as string), and I want my original search to do a boolean filter on the original free text search.

I am thinking that this must be done using a BooleanQuery and then doing a combine with the original MultiFieldQueryParser and the new BooleanQuery.

Is that right way to go about doing this?

3
  • 1
    You can also create a QueryFilter and give it to Search method Commented Feb 1, 2012 at 11:32
  • Thanks for the reply, could you give me an example of this? Commented Feb 1, 2012 at 13:57
  • 1
    Like LB said i'd build 2 QueryFilters, one for 0 and one for 1. Then you keep them around and re-use them. You need to rebuild the Filters only when the index changes. QueryFilter caches the matching docs so you should see a performance increase over using a plain BooleanQuery clause Commented Feb 1, 2012 at 14:02

1 Answer 1

1

Example of a QueryFilter for a 'false' value

QueryFilter falseFilter = new QueryFilter(new TermQuery(new Term("BOOL_FIELD", "0")));
searcher.search(query, falseFilter, maxResults);
Sign up to request clarification or add additional context in comments.

2 Comments

can I just ask, is it possible to use multiple filters?
yes, using the BooleanFilter in the Lucene.net contrib package, it is in the Lucene.Net.Search namespace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.