Multiple filters in Lucene.net
How to combine multiple filters within one search?
For example I have record with analyzable field title and not analyzable fields id1, id2, id3, release_date. I want to find all records using specific filters for id1, id2, id3 and release_date; So, I have:
RangeFilter refReleaseDateFilter = new RangeFilter("release_date",
refFromDateTimeTerm.Text(), refToDateTimeTerm.Text(), true, true);
RangeFilter refId1Filter = new RangeFilter("id1",
开发者_如何学Python refFromId1Term.Text(), refToId1Term.Text(), true, true);
RangeFilter refId2Filter = new RangeFilter("id2",
refFromId2Term.Text(), refToId2Term.Text(), true, true);
RangeFilter refId3Filter = new RangeFilter("id3",
refFromId3Term.Text(), refToId3Term.Text(), true, true);
But the method Search of class IndexSearcher does not provide array of filters.
Please help me:) Thank you!:)
You may use something like a ChainedFilter
see.: http://lucene.apache.org/java/2_9_0/api/contrib-misc/org/apache/lucene/misc/ChainedFilter.html
there is also a ChainedFilter in the .net distribution of lucene.
http://www.koders.com/csharp/fidB8682543372DDC9772496D453F39957A94E58466.aspx?s=system#L3
Another option would be to implement it as a port of the java application it is not that much code.
Using a single BooleanQuery
worked for me with Lucene.NET 3.0.3:
var filters = new BooleanQuery();
filters.Add(new TermQuery(new Term("ancestor_path", path)), Occur.MUST);
filters.Add(new TermQuery(new Term("resource_type", "page")), Occur.MUST);
var filter = new QueryWrapperFilter(filters);
精彩评论