Reputation: 155145
All of my Lucene.net (2.9.2) documents have two fields:
bodytext
is the default field, and is where all of the document's text is stored (using Field.Store.NO , Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS
).
categoryid
is just a numeric field stored as text: Field.Store.YES, Field.Index.NOT_ANALYZED
When this query is executed, it only returns documents with that category ID: categoryid:1
However when I perform this query: categoryid:1 foo bar
it returns documents from other categories other than 1.
Why is this? And how can I force it to respect the original categoryid:N
query term?
Upvotes: 1
Views: 108
Reputation: 19781
Do you want to require all words entered to be present in your matched documents?
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
var queryParser = new QueryParser(Version.LUCENE_30, "bodytext", analyzer);
// This ensures that all terms are required.
queryParser.DefaultOperator = QueryParser.Operator.AND;
var query = queryParser.Parse("categoryid:1 foo bar");
// query = "+categoryid:1 +bodytext:foo +bodytext:bar"
Upvotes: 3