Marcel
Marcel

Reputation: 105

Lucene behaviour boolean query

I am experiencing weird behaviour with a BooleanQuery. Let's say my index looks like this:

text: bla bla2 moreinfo hi
user: 123

Then I have the following code:

QueryParser parser = new QueryParser('text', new StandardAnalyzer());   
Query q = parser.parse(searchString);
BooleanQuery booleanQuery = new BooleanQuery.Builder()
            .add(q, Occur.MUST) 
            .build();

With this code, if I search for 'bl' it will give me a result (match on 'bla'). Now I add a user constraint to this booleanQuery, like this:

QueryParser parser = new QueryParser('text', new StandardAnalyzer());   
Query q = parser.parse(searchString);
TermQuery userQuery = new TermQuery(new Term('user','123'));
BooleanQuery booleanQuery = new BooleanQuery.Builder()
            .add(q, Occur.MUST) 
            .add(userQuery, Occur.MUST)
            .build();

Now, suddenly 'bl' does not return anything. However, searching for 'bla' or 'bl*' does.

So it seems like the behaviour of the query 'q' changes because I added another clause to the booleanQuery.

I am trying to understand why this happens? Ps. I prefer to be able to search on 'bl' instead of having to use 'bl*'.

Upvotes: 0

Views: 37

Answers (0)

Related Questions