how do i filter my lucene search results?

Posted by Andrew Bullock on Stack Overflow See other posts from Stack Overflow or by Andrew Bullock
Published on 2009-08-13T10:43:19Z Indexed on 2010/04/18 7:03 UTC
Read the original article Hit count: 353

Say my requirement is

"search for all users by name, who are over 18"

If i were using SQL, i might write something like:

Select * from [Users]
Where ([firstname] like '%' + @searchTerm + '%' OR 
       [lastname] like '%' + @searchTerm + '%')
    AND [age] >= 18

However, im having difficulty translating this into lucene.net.

This is what i have so far:

var parser = new MultiFieldQueryParser({ "firstname", "lastname"}, new StandardAnalyser());
var luceneQuery = parser.Parse(searchterm)

var query = FullTextSession.CreateFullTextQuery(luceneQuery, typeof(User));

var results = query.List<User>();

How do i add in the "where age >= 18" bit?

I've heard about .SetFilter(), but this only accepts LuceneQueries, and not IQueries. If SetFilter is the right thing to use, how do I make the appropriate filter? If not, what do I use and how do i do it?

Thanks!

P.S. This is a vastly simplified version of what I'm trying to do for clarity, my WHERE clause is actually a lot more complicated than shown here. In reality i need to check if ids exist in subqueries and check a number of unindexed properties. Any solutions given need to support this.

Thanks

© Stack Overflow or respective owner

Related posts about lucene

Related posts about lucene.net