lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Todd VanderVeen <...@part.net>
Subject Re: Optional Terms in a single query
Date Tue, 22 Feb 2005 00:01:08 GMT
Luke Shannon wrote:

>Hi Tod;
>
>Thanks for your help.
>
>I was able to do what you said but in a much uglier way using a Boolean
>Query and adding Wildcard Queries.
>
>The end result looks like this:
>
>The query: +(type:138) +((-name:*tim* -name:*bill* -name:*harry*
>+olfaithfull:stillhere))
>
>But this one works as expected.
>
>Thanks!
>
>Luke
>----- Original Message ----- 
>From: "Todd VanderVeen" <tdv@part.net>
>To: "Lucene Users List" <lucene-user@jakarta.apache.org>
>Sent: Monday, February 21, 2005 6:26 PM
>Subject: Re: Optional Terms in a single query
>
>
>  
>
>>Luke Shannon wrote:
>>
>>    
>>
>>>The API I'm working with combines a series of queries into one larger one
>>>using a boolean query.
>>>
>>>Queries on the same field get OR's into one big query. All remaining
>>>      
>>>
>queries
>  
>
>>>are AND'd with this big one.
>>>
>>>Working with in this system I have:
>>>
>>>arg = (mario luigi bobby joe) //i do have control of how this list is
>>>created
>>>
>>>I pass this to the QueryParser:
>>>
>>>Query query1 = QueryParser.parse(arg, "name", new StandardAnalyzer());
>>>Query query2 = QueryParser.parse("stillhere", "olfaithfull", new
>>>StandardAnalyzer());
>>>BooleanQuery typeNegativeSearch = new BooleanQuery();
>>>typeNegativeSearch.add(query1, false, true);
>>>typeNegativeSearch.add(query2, true, false);
>>>
>>>This is half the query.
>>>
>>>It gets AND'd with the other half, to create what you see below:
>>>
>>>+(type:181) +((-(name:tim name:harry name:bill) +olfaithfull:stillhere))
>>>
>>>What I am having trouble with is getting the QueryParser to create
>>>this: -name:(tim bill harry)
>>>
>>>I feel like this is something simple, but for some reason I can't figure
>>>      
>>>
>it
>  
>
>>>out.
>>>
>>>Thanks,
>>>
>>>Luke
>>>
>>>
>>>
>>>      
>>>
>>Is the API something you control?
>>
>>Lets call the other half of you query query3. To avoid the extra nesting
>>you need to do the composition in a single boolean query.
>>
>>Query query1 = QueryParser.parse(arg, "name", new StandardAnalyzer());
>>Query query2 = QueryParser.parse("stillhere", "olfaithfull", new
>>    
>>
>StandardAnalyzer());
>  
>
>>Query query3 = ....
>>
>>BooleanQuery finalQuery = new BooleanQuery();
>>finalQuery.add(query1, false, true);
>>finalQuery.add(query2, true, false);
>>finalQuery.add(query3, true, false);
>>
>>Cheers,
>>Todd VanderVeen
>>
>>---------------------------------------------------------------------
>>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
>
>  
>
I would be careful using wildcards as proposed. They can be inefficient 
(particularly in a list of disjunctions) but even more importantly you 
are excluding more than the 3 names. Your results won't be consistent 
with your intent.

Cheers,
Todd VanderVeen



---------------------------------------------------------------------
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