lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erick Erickson <erickerick...@gmail.com>
Subject Re: Use boolean operator "-", the result is incorrect
Date Wed, 08 Apr 2020 12:53:47 GMT
Solr/Lucene do not employ boolean logic. See Hossman’s excellent post:

https://lucidworks.com/post/why-not-and-or-and-not/

Until you internalize this rather subtle difference, you’ll be surprised. A lot ;).

You can make query parsing look a lot like boolean logic by carefully using parentheses…

Best,
Erick

> On Apr 8, 2020, at 6:38 AM, Bernd Fehling <bernd.fehling@uni-bielefeld.de> wrote:
> 
> About first query, you have a negative query telling the searcher to give only
> results _NOT_ containing "name_s:a". From that result list you want only
> results of "age_i:10".
> Boolean table for OR is:
> 0 OR 0 = 0
> 1 OR 0 = 1
> 0 OR 1 = 1
> 1 OR 1 = 1
> You get one result.
> 
> About second query your "parsedquery" says you _must_ have id:1 OR id:2
> (where you will get both) but _must_ _not_ have anything with "name_s:a".
> But you have something with "name_s:a", so you get no results.
> 
> Regards
> Bernd
> 
> Am 08.04.20 um 11:53 schrieb slly:
>> My default query operator is OR.There are two pieces of data in the index:
>> { "id":"1", "name_s":"a", "age_i":10, "_version_":1663396766955864064}, { "id":"2",
"name_s":"b", "age_i":10, "_version_":1663396767058624512}] }
>> 
>> 
>>  1.   -name_s:a OR age_i:10          # I think two pieces of data should be returned,
but only one
>> 
>> "rawquerystring":"-name_s:a age_i:10", "querystring":"-name_s:a age_i:10", "parsedquery":"-name_s:a
IndexOrDocValuesQuery(age_i:[10 TO 10])", "parsedquery_toString":"-name_s:a age_i:[10 TO 10]",
"QParser":"LuceneQParser",
>> 
>> 
>> 
>>  2.  id:("1" "2") AND (-name_s:a) # I think one data should be returned, but 0 data

>> 
>> "rawquerystring":"id:(\"1\" \"2\") AND (-name_s:a)", "querystring":"id:(\"1\" \"2\")
AND (-name_s:a)", "parsedquery":"+(id:1 id:2) +(-name_s:a)", "parsedquery_toString":"+(id:1
id:2) +(-name_s:a)", "QParser":"LuceneQParser",
>> 
>> 
>> 
>> 
>> 
>> At 2020-04-08 17:46:37, "Bernd Fehling" <bernd.fehling@uni-bielefeld.de> wrote:
>>> What is debugQuery telling you about:
>>> - "rawquerystring"
>>> - "querystring"
>>> - "parsedquery"
>>> - "parsedquery_toString"
>>> - "QParser"
>>> 
>>> Also what is your default query operator, AND or OR?
>>> This is what matters for your second example with  id:("1" "2")
>>> It could be  id:("1" AND "2")  or  id:("1" OR "2") .
>>> 
>>> Regards
>>> Bernd
>>> 
>>> Am 08.04.20 um 11:30 schrieb slly:
>>>> Thanks Bernd for your reply.
>>>> I run the query on the Solr Web UI in Solr 7.3.1/7.7.2, the screenshot of
my execution results is as follows,  I don't understand whether there is a grammatical error
?
>>>> 1. -name_s:a OR age_i:10
>>>> 
>>>> 2. id:("1" "2") AND (-name_s:a)
>>>> 
>>>> 
>>>> At 2020-04-08 16:33:20, "Bernd Fehling" <bernd.fehling@uni-bielefeld.de>
wrote:
>>>>> Looks correct to me.
>>>>> 
>>>>> You have to obey the level of the operators and the parenthesis.
>>>>> Turn debugQuery on to see the results of parsing of your query.
>>>>> 
>>>>> Regards
>>>>> Bernd
>>>>> 
>>>>> Am 08.04.20 um 09:34 schrieb slly:
>>>>>> 
>>>>>> 
>>>>>> If the following query is executed, the result is different:
>>>>>> 
>>>>>> 
>>>>>> id:("1" "2") AND (-name_s:a)     --> numFound is 0 
>>>>>> 
>>>>>> 
>>>>>> id:("1" "2") AND -(name_s:a)    --> numFound is 1 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> At 2020-04-08 14:56:26, "slly" <sllyjw@126.com> wrote:
>>>>>>> Hello Folks,
>>>>>>> We are using Solr 7.3.1,  I write the following two lines of
data into collection:
>>>>>>> id, name_s, age_i
>>>>>>> 1, a, 10
>>>>>>> 2, b, 10
>>>>>>> Use the following query syntax:
>>>>>>> -name_s:a OR age_i:10
>>>>>>> 
>>>>>>> 
>>>>>>> I think we should return two pieces of data, but actually only
one piece of data:
>>>>>>> id, name_s, age_i
>>>>>>> 2, b, 10
>>>>>>> 
>>>>>>> 
>>>>>>> Did I get it wrong?  Looking forward to some valuable suggestions.
Thanks.
>>>> 


Mime
View raw message