You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Klaus <kl...@vommond.de> on 2006/01/11 19:30:06 UTC

Boolean Query

Hi,

I have got another question... How do I construct a BooleanQuery, where the
terms with the query a connected with OR? 

I have a list of term, representing to high scored terms in a document. Here
is my code

BooleanQuery query = new BooleanQuery();
for(Term t: terms)
{
	query = new TermQuery(t);
	query.add(t, false, false); // ist his wrong?	  
}

If I construct the query as a string like "A a OR B b OR C" I get much more
results. I assume that the Boolean query uses an AND operator. How can I
change that. 

And I'm wondering what happens if I boost a TermQuery with a value smaller
then one. I'm asking because I would like to boost each TermQuery with the
td*idf Value of the term in the original document. From my point of view,
this should lead to a better precision, but on the first looks the results
are worse.

THX,

Klaus



---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Boolean Query

Posted by Chris Hostetter <ho...@fucit.org>.
: BooleanQuery query = new BooleanQuery();
: for(Term t: terms)
: {
: 	query = new TermQuery(t);
: 	query.add(t, false, false); // ist his wrong?
: }
:
: If I construct the query as a string like "A a OR B b OR C" I get much more
: results. I assume that the Boolean query uses an AND operator. How can I
: change that.

The "false, false" on when you add the subclauses should be doing the "OR"
behavior, but more then likely the problem you are running into has to do
with the analyzer being used by your QueryParser when it parses your
string -- when you build the query up by hand, no analyzer is used, so if
the analyzer used at indexing time did any lowercasing or steming you'll
miss a lot of matches.

a quick thing you should try is comparing the toString from each of the
queries you are comparing (the one QueryParser built, and the one you
built by hand).  You should also look at this wiki entry, and pick up a
copy of Lucene in Action and read chapter 4.

: And I'm wondering what happens if I boost a TermQuery with a value smaller
: then one. I'm asking because I would like to boost each TermQuery with the
: td*idf Value of the term in the original document. From my point of view,
: this should lead to a better precision, but on the first looks the results
: are worse.

Before you try this, make sure you understand the existing score
claculation ... look a the explain info for each document against your
query and see what it's already doing.


-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org