1

I have three fields in the index; firstname, lastname, and isManager (1 or 0). How do I go about using the QueryParser and add isManager (as a global filter) to 1 only so that I am effectively searching for the managers only?

So, if user searches for/passes in "firstname:john", I would like to add/append "isManager:1" as a global filter. One solution is to append "NOT isManager:0" to all the user's query string... but was wondering if there's any other preferred way.

2 Answers 2

0

Wrap the Query object you get back from QueryParer using FilteredQuery http://lucene.apache.org/core/4_0_0/core/org/apache/lucene/search/FilteredQuery.html

0

Using query filters is the right way to do it.

The problem with appending is that theoretically this is prone to query injection attacks (think SQL injection but for Lucene queries).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.