How do I filter lucene search results?

Say my requirement

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

If I were using SQL, I could write something like:

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

However, it is difficult for them to translate this to lucene.net.

This is what I still have:

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 to add in "where age> = 18" bits?

I heard about .SetFilter(), but it only accepts LuceneQueries, not IQueries. If SetFilterused correctly, how can I make an appropriate filter? If not, what am I using and how to do it?

Thanks!

P.S. , , WHERE , . , . .

+3
3

NHibernate.Search lucene, , HQL where, .

: NH.Search , . , NH.S, , . .

+1

, Lucene:

age:[18 TO 100]

, QueryWrapperFilter. , Nhibernate Search. "AND", . , .

+2

QueryWrapperFilter.

+1

Source: https://habr.com/ru/post/1715061/


All Articles