lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Gullestad Pettersen <>
Subject No hits when querying multiple fields
Date Tue, 27 Jul 2010 20:18:38 GMT
Consider the following two documents which I have added to my index:

doc.add( new Field("text", "hello world", Field.Store.YES,
> Field.Index.ANALYZED));
> doc.add( new Field("id", "1", Field.Store.YES, Field.Index.ANALYZED));

Using the StandardQueryParser I can retrieve my document with either of
these two queries:

1) title:"hello world"

> 2) id:"1"

however, if I try AND'ing the above two, I get 0 results:

> 3) title:"hello world" AND id:"1"

If I remove the AND  and modify the first term to something that i know is
not in my document, I also find my document:

> 4) title:"no match" id:"1"
> i guess leaving out the keywork AND turns it into an OR query, not what
I want.

In the debugging process I have tried passing the toString() of the Query
object returned from the StandardQueryParser to System.out, and it shows the
following for the above queries:
1) *title:"hello world"* ->Query.toString()->* title:"hello world"*
2) *id:"1" ->* Query.toString ->* id:1*
3) *title:"hello world" AND id:"1"* -> Query.toString() -> *+title:"hello
world" +id:1*
4) *title:"hello world" id:"1"* -> Query.toString() -> *title:"hello world"

*The only things noticable is quotations being removed from the "id"-term,
and  #3 where the AND is removed and a + is prefixed the field names.
Iunderstand that the + sign in front of the field name means that the term
has to exist in that field, so essentially my queries seem to have been
parsed as expected

Queries 1,2 and 4 all return results as expected, but can anyone tell me why
number #3 - the AND query - does not return my document? it is essentially
an AND between query #1 and #2 which both match the document.

I have also tried construction a query manually:

BooleanQuery query = new BooleanQuery();
> TermQuery textQuery = new TermQuery(new Term("text","hello world"));
> TermQuery idQuery = new TermQuery(new Term("id","1"));
> query.add(textQuery, Occur.MUST);
> query.add(iddQuery, Occur.MUST);

.. but just as with the above query #3 I get nothing back. passing this
Query's toString() output to System.out also gives me the same as for #3:
5) *title:"hello world" AND id:"1"* -> Query.toString() -> *+title:"hello
world" +id:"1"*

Can anyone please tell me what I'm doing wrong? I just want to and queries
#1 and #2 which both match my document when executed alone..

Thank you very much,
Geir Pettersen

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message