lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Chandler <>
Subject Re: Confused about boolean query and how an IndexReader is associated with Hits
Date Wed, 07 Dec 2005 15:45:31 GMT
On Wednesday 07 Dec 2005 07:38, Alan Chandler wrote:
> I am trying to construct, via individual query api, a query to search for
> documents with a field name of "Category" and a value of either "Category1"
> OR "Category2" (or both).
> My code to do this (given categories is the set of strings with the
> category names I wish to search for) is as follows
> 		BooleanQuery query = new BooleanQuery();

Actually I cheated a little when I posted that. Because I missed out  ...

		query.add(config,false,true); //This clause misses out the config document
		if (onlyPublished) {
			query.add(published,true,false); // limit to published articles

> 		if (categories != null && !categories.isEmpty()) {
> 			for (String category : categories) {
> 				TermQuery t =new TermQuery(new Term("Category",category));
> 				query.add(t,false,false); //Saywould like that category
> 			}
> 		}

In otherwords my BooleanQuery was more complex than I let on.

Now I have solved the other problem or getting to see the Hits without an 
IOException (by keeping the indexWriter open) I can see that what is returned 
is ONLY the document defined by the first term (ie labelled config in the 
above code snippet).

(My config document has the field "ID" set to value "0" - all the other 
documents have a single field called "ID" set to the string of a positive 
integer so config is defined as 

private static final TermQuery config =new TermQuery(new Term("ID","0"));

I thought that term, with the "prohibited" set to true prevented this one 
being a match.

What I seem to have is therefore the inverse of what I was expecting - so what 
have I misunderstood here?

Alan Chandler
Open Source. It's the difference between trust and antitrust.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message