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 John Fereira <ja...@cornell.edu> on 2005/06/24 20:54:59 UTC

QueryParser implicit conjunction

Last month there was a brief thread about changing the implicit conjuction 
for search terms from an OR to AND with a response that the API provides a 
setOperator method for doing so.

A site I am developing also required that "AND" be the implicit conjuction 
so I've tried changing that using the QueryParser.setOperator(1) method. I 
put in some logging to confirm that the implicit operator is changing but 
the search results still seem to be producing results using ORing the 
terms.  Here's what the code looks like:

QueryParser qp = new QueryParser( queryField, analyzer);
logger.info("operator before: "+qp.getOperator());
qp.setOperator(1);
logger.info("operator after: "+qp.getOperator());
query = qp.parse(searchterms, queryField, analyzer);

In the log files it shows that the operator is 0 before the setOperator(1) 
call has been made, and returns a 1 afterwords.  However, when the search 
is performed it still seems to OR the terms.

As a workaround, we just changed the default operator setting in 
QueryParser.java and rebuilt the jar file but I would prefer to use an 
official release so that we can update without applying our patch.





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


Re: QueryParser implicit conjunction

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jun 25, 2005, at 5:13 PM, John Fereira wrote:

> At 02:42 PM 6/25/2005 +0200, Daniel Naber wrote:
>
>> On Saturday 25 June 2005 13:59, John Fereira wrote:
>>
>> > Was there someplace that I should have looked to determine that
>> > qp.parse(String) would call the non-static method but qp.parse 
>> (String,
>> > String, Analyzer) would not?
>>
>> Your IDE should have warned you about that. If it didn't, try  
>> Eclipse.
>>
>
> I usually don't use an IDE and am familiar with Eclipse, IntelliJ,  
> NetBeans, etc.   When I started programming on *nix systems 21  
> years ago we didn't have them so I just got used to working from a  
> command shell.

See what you're missing?!  :)

I really admire and respect the folks that do Java without an IDE.   
Doug wrote Lucene with emacs, and that is a skill in and of itself to  
be revered.  But I view Java source code as a rich interconnected  
web.  Surfing it with an IDE(A!) is definitely my preference.

     Erik


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


Re: QueryParser implicit conjunction

Posted by John Fereira <ja...@cornell.edu>.
At 02:42 PM 6/25/2005 +0200, Daniel Naber wrote:
>On Saturday 25 June 2005 13:59, John Fereira wrote:
>
> > Was there someplace that I should have looked to determine that
> > qp.parse(String) would call the non-static method but qp.parse(String,
> > String, Analyzer) would not?
>
>Your IDE should have warned you about that. If it didn't, try Eclipse.

I usually don't use an IDE and am familiar with Eclipse, IntelliJ, 
NetBeans, etc.   When I started programming on *nix systems 21 years ago we 
didn't have them so I just got used to working from a command shell.

John Fereira
jaf30@cornell.edu
Ithaca, NY


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


Re: QueryParser implicit conjunction

Posted by Daniel Naber <lu...@danielnaber.de>.
On Saturday 25 June 2005 13:59, John Fereira wrote:

> Was there someplace that I should have looked to determine that
> qp.parse(String) would call the non-static method but qp.parse(String,
> String, Analyzer) would not?

Your IDE should have warned you about that. If it didn't, try Eclipse.

Regards
 Daniel

-- 
http://www.danielnaber.de

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


Re: QueryParser implicit conjunction

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jun 25, 2005, at 7:59 AM, John Fereira wrote:
>> Aha!  Look at the method signature of your parse() call.  That is the
>> culprit.  To call the non-static method so that you use the
>> *instance* of QueryParser rather than the default settings, change to
>> this:
>>
>>     query = qp.parse(searchterms);
>>
>
> Thanks, that fixed it.
>
>   Was there someplace that I should have looked to determine that  
> qp.parse(String) would call the non-static method but qp.parse 
> (String, String, Analyzer) would not?

Besides Daniel's comment about IDE's warning of this (calling a  
static method from an instance variable is usually a warning), you  
can also glean this information from Lucene's Javadocs.  The static  
parse method is more trouble than its worth, actually.  We should  
probably deprecate that for 1.9 and remove it in 2.0 and only allow  
QueryParser instances - this allows more flexibility with things like  
MultiFieldQueryParser and such too.

     Erik


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


Re: QueryParser implicit conjunction

Posted by John Fereira <ja...@cornell.edu>.
At 03:42 PM 6/24/2005 -0400, you wrote:

>On Jun 24, 2005, at 2:54 PM, John Fereira wrote:
>
>>
>>Last month there was a brief thread about changing the implicit
>>conjuction for search terms from an OR to AND with a response that
>>the API provides a setOperator method for doing so.
>>
>>A site I am developing also required that "AND" be the implicit
>>conjuction so I've tried changing that using the
>>QueryParser.setOperator(1) method. I put in some logging to confirm
>>that the implicit operator is changing but the search results still
>>seem to be producing results using ORing the terms.  Here's what
>>the code looks like:
>>
>>QueryParser qp = new QueryParser( queryField, analyzer);
>>logger.info("operator before: "+qp.getOperator());
>>qp.setOperator(1);
>>logger.info("operator after: "+qp.getOperator());
>>query = qp.parse(searchterms, queryField, analyzer);
>>
>>In the log files it shows that the operator is 0 before the
>>setOperator(1) call has been made, and returns a 1 afterwords.
>>However, when the search is performed it still seems to OR the terms.
>>
>>As a workaround, we just changed the default operator setting in
>>QueryParser.java and rebuilt the jar file but I would prefer to use
>>an official release so that we can update without applying our patch.
>
>Aha!  Look at the method signature of your parse() call.  That is the
>culprit.  To call the non-static method so that you use the
>*instance* of QueryParser rather than the default settings, change to
>this:
>
>     query = qp.parse(searchterms);

Thanks, that fixed it.

   Was there someplace that I should have looked to determine that 
qp.parse(String) would call the non-static method but qp.parse(String, 
String, Analyzer) would not?


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


Re: QueryParser implicit conjunction

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jun 24, 2005, at 2:54 PM, John Fereira wrote:

>
> Last month there was a brief thread about changing the implicit  
> conjuction for search terms from an OR to AND with a response that  
> the API provides a setOperator method for doing so.
>
> A site I am developing also required that "AND" be the implicit  
> conjuction so I've tried changing that using the  
> QueryParser.setOperator(1) method. I put in some logging to confirm  
> that the implicit operator is changing but the search results still  
> seem to be producing results using ORing the terms.  Here's what  
> the code looks like:
>
> QueryParser qp = new QueryParser( queryField, analyzer);
> logger.info("operator before: "+qp.getOperator());
> qp.setOperator(1);
> logger.info("operator after: "+qp.getOperator());
> query = qp.parse(searchterms, queryField, analyzer);
>
> In the log files it shows that the operator is 0 before the  
> setOperator(1) call has been made, and returns a 1 afterwords.   
> However, when the search is performed it still seems to OR the terms.
>
> As a workaround, we just changed the default operator setting in  
> QueryParser.java and rebuilt the jar file but I would prefer to use  
> an official release so that we can update without applying our patch.

Aha!  Look at the method signature of your parse() call.  That is the  
culprit.  To call the non-static method so that you use the  
*instance* of QueryParser rather than the default settings, change to  
this:

     query = qp.parse(searchterms);

Erik



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