lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: Lucene Query Parsing versus Programmatic Query Building with API
Date Sun, 24 Dec 2006 09:45:28 GMT
Did anyone reply to this yet?

On Dec 21, 2006, at 6:30 PM, Andy Berryman wrote:
> Example:  Find all documents with the phrase "star wars dvd" in  
> Contents
> that have a DocID beginning with "ZXY".
>
> (Contents:"star wars dvd") AND (DocID:ZXY*)
>
> What I'd like to know is how to build this programmatically instead  
> of using
> the QueryParser.  I have a general idea, but I'm looking for some  
> help and
> validation from the group please.  Can someone out there give me a  
> hand?

Have a look at the javadocs for all the Query subclasses, and the  
source code to QueryParser (ignoring all the JavaCC gunk in the  
way).  Also, there are lots of examples of this in "Lucene in Action"  
and the free code you can snag at lucenebook.com.

> Also ... Another question I have is about the Analyzer's  
> involvement here.
> When you use the QueryParser object, you pass in the particular  
> Analyzer (in
> my case its the StandardAnalyzer) you would like to use when  
> analyzing the
> text provided in the parse string.  Why is it that when you are  
> building the
> query programmatically, that you dont ever have to specify an Analyzer
> object?  I say this because I've been unable to find that
> functionality/parameter/property anywhere.  I'm probably missing  
> something
> simple here, but it's just not making since to me.

Analyzing text is not something the Query subclasses should be doing,  
but rather, as you're experiencing, it is delegated to the client of  
the Query subclasses.  You'll find it quite easy (only a few lines of  
code).  Check out the AnalysisDemo code (particularly the analyze  
method) here:

	<http://today.java.net/pub/a/today/2003/07/30/LuceneIntro.html>

That'll give you exactly what you want, and just insert adding  
clauses to a BooleanQuery or something like that inside the loop of  
terms (like QueryParser does).

	Erik


Mime
View raw message