lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Smith <SSm...@MainstreamData.com>
Subject RE: Query question
Date Tue, 13 Jan 2004 22:21:39 GMT
So I can write:

	Query q2 = new TermQuery(new Term("a1", "FieldA"));

And similar things for all of the QueryParser's.  This makes sense and I
assume must be more efficient than using the QueryParser for simple terms.

As you have guessed, there may be an arbitrary number of terms (not just 2)
but they are all simple words.  Some of the terms are generated
programmatically and not entered explicitly by the user.  But the code below
(even using TermQuery) seems like it should generalize to an arbitrary
number of terms.

I guess what is confusing me now is that the search code no longer
references an analyzer???!!!  How does it know how to tokenize, stem, etc.
the search terms?

Thanks for the help

Scott

-----Original Message-----
From: Erik Hatcher [mailto:erik@ehatchersolutions.com] 
Sent: Tuesday, January 13, 2004 6:27 AM
To: Lucene Users List
Subject: Re: Query question


On Jan 12, 2004, at 7:49 PM, Scott Smith wrote:
> Does the following do that:
>
> 	BooleanQuery Query QA = new Boolean Query();
> 	Query qa1 = QueryParser.parse("A1", "FieldA", analyzer());
> 	Query qa2 = QueryParser.parse("A2", "FieldA", analyzer());
> 	QA.add(qa1, false, false);	// this term is not required
> 	QA.add(qa2, false, false);	// this term is not required
>
> 	BooleanQuery QB = new BooleanQuery();
> 	Query qb1 = QueryParser.parse("B1", "FieldB", analyzer());
> 	Query qb2 = QueryParser.parse("B2", "FieldB", analyzer());
> 	QB.add(qb1, false, false);	// this term is not required
> 	QB.add(qb2, false, false);	// this term is not required
>
> 	BooleanQuery Qfinal = new BooleanQuery();
> 	Qfinal.add(QA, true, false);	// gotta have at least one from here
> 	Qfinal.add(QB, true, false);	// gotta have at least one from here
>
> 	hits = mySearcher.search(Qfinal);

Your use of QueryParser is unnecessary.  Simply construct TermQuery's 
instead.   Otherwise, what you are doing looks fine.

> I guess I'm assuming that if I add a queries to a BooleanQuery and
> none of
> the items are required, there still needs to be a hit on at least one 
> of the
> items for the Document to make it out of the BooleanQuery.

Right.   A OR B means that either A or B have to be present, but if 
neither are present then there is no match.

> Is this the right way to do this?  Is there an easier/faster way to do
> the
> same thing?

You're asking a pretty general question - are you really just using two 
terms for each field?  What you've shown based on the example (with the 
exception of using QueryParser) is fine.

	Erik


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

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


Mime
View raw message