You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Lan <du...@gmail.com> on 2012/03/12 00:36:49 UTC

Strange behavior with search on empty string and NOT

I am curious why solr results are inconsistent for the query below for an
empty string search on a TextField. 

q=name:"" returns 0 results
q=name:"" AND NOT name:"FOOBAR" return all results in the solr index. Should
it should not return 0 results too?

Here is the debugQuery.

<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
<lst name="params">
<str name="debugQuery">on</str>
<str name="indent">on</str>
<str name="start">0</str>
<str name="q">name:"" AND NOT name:"BLAH232282"</str>
<str name="rows">0</str>
<str name="version">2.2</str>
</lst>
</lst>
<result name="response" numFound="3790790" start="0"/>
<lst name="debug">
<str name="rawquerystring">name:"" AND NOT name:"BLAH232282"</str>
<str name="querystring">name:"" AND NOT name:"BLAH232282"</str>
<str name="parsedquery">-PhraseQuery(name:"blah 232282")</str>
<str name="parsedquery_toString">-name:"blah 232282"</str>
<lst name="explain"/>
<str name="QParser">LuceneQParser</str>
<lst name="timing">
<double name="time">1.0</double>
<lst name="prepare">
<double name="time">1.0</double>
<lst name="org.apache.solr.handler.component.QueryComponent">
<double name="time">1.0</double>
</lst>
<lst name="org.apache.solr.handler.component.FacetComponent">
<double name="time">0.0</double>
</lst>
<lst name="org.apache.solr.handler.component.MoreLikeThisComponent">
<double name="time">0.0</double>
</lst>
<lst name="org.apache.solr.handler.component.HighlightComponent">
<double name="time">0.0</double>
</lst>
<lst name="org.apache.solr.handler.component.StatsComponent">
<double name="time">0.0</double>
</lst>
<lst name="org.apache.solr.handler.component.DebugComponent">
<double name="time">0.0</double>
</lst>
</lst>
<lst name="process">
<double name="time">0.0</double>
<lst name="org.apache.solr.handler.component.QueryComponent">
<double name="time">0.0</double>
</lst>
<lst name="org.apache.solr.handler.component.FacetComponent">
<double name="time">0.0</double>
</lst>
<lst name="org.apache.solr.handler.component.MoreLikeThisComponent">
<double name="time">0.0</double>
</lst>
<lst name="org.apache.solr.handler.component.HighlightComponent">
<double name="time">0.0</double>
</lst>
<lst name="org.apache.solr.handler.component.StatsComponent">
<double name="time">0.0</double>
</lst>
<lst name="org.apache.solr.handler.component.DebugComponent">
<double name="time">0.0</double>
</lst>
</lst>
</lst>
</lst>
</response>


--
View this message in context: http://lucene.472066.n3.nabble.com/Strange-behavior-with-search-on-empty-string-and-NOT-tp3818023p3818023.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Strange behavior with search on empty string and NOT

Posted by Chris Hostetter <ho...@fucit.org>.
: Would it be a good idea to have Solr throw syntax error if an empty string
: query occurs? 

erick's explanation wasn't very precise ... 

solr doesn't have any special handling of "empty strings", but what you 
are searching for *might* be a totally valid query based on how the field 
type is configured (ie: strfield, or keywordtokenizer, etc...

in your case, you seem to be seraching for "" in a field for the 
analyzer produces no tokens for "", so it falls out of the query.


-Hoss

Re: Strange behavior with search on empty string and NOT

Posted by Lan <du...@gmail.com>.
Would it be a good idea to have Solr throw syntax error if an empty string
query occurs? 



--
View this message in context: http://lucene.472066.n3.nabble.com/Strange-behavior-with-search-on-empty-string-and-NOT-tp3818023p3823572.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Strange behavior with search on empty string and NOT

Posted by Erick Erickson <er...@gmail.com>.
Because Lucene query syntax is not a strict Boolean logic system.
There's a good explanation here:
http://www.lucidimagination.com/blog/2011/12/28/why-not-and-or-and-not/

Adding &debugQuery=on to your search is your friend <G>.. You'll see
that your return (at least on 3.5 with going at /solr/select) returns
this as the parsed query:

<str name="parsedquery">-name:foobar</str>

Solr really doesn't have the semantics for empty strings (or NULL for
that matter) so it just gets dropped out.

Best
Erick

On Sun, Mar 11, 2012 at 11:36 PM, Lan <du...@gmail.com> wrote:
> I am curious why solr results are inconsistent for the query below for an
> empty string search on a TextField.
>
> q=name:"" returns 0 results
> q=name:"" AND NOT name:"FOOBAR" return all results in the solr index. Should
> it should not return 0 results too?
>
> Here is the debugQuery.
>
> <response>
> <lst name="responseHeader">
> <int name="status">0</int>
> <int name="QTime">1</int>
> <lst name="params">
> <str name="debugQuery">on</str>
> <str name="indent">on</str>
> <str name="start">0</str>
> <str name="q">name:"" AND NOT name:"BLAH232282"</str>
> <str name="rows">0</str>
> <str name="version">2.2</str>
> </lst>
> </lst>
> <result name="response" numFound="3790790" start="0"/>
> <lst name="debug">
> <str name="rawquerystring">name:"" AND NOT name:"BLAH232282"</str>
> <str name="querystring">name:"" AND NOT name:"BLAH232282"</str>
> <str name="parsedquery">-PhraseQuery(name:"blah 232282")</str>
> <str name="parsedquery_toString">-name:"blah 232282"</str>
> <lst name="explain"/>
> <str name="QParser">LuceneQParser</str>
> <lst name="timing">
> <double name="time">1.0</double>
> <lst name="prepare">
> <double name="time">1.0</double>
> <lst name="org.apache.solr.handler.component.QueryComponent">
> <double name="time">1.0</double>
> </lst>
> <lst name="org.apache.solr.handler.component.FacetComponent">
> <double name="time">0.0</double>
> </lst>
> <lst name="org.apache.solr.handler.component.MoreLikeThisComponent">
> <double name="time">0.0</double>
> </lst>
> <lst name="org.apache.solr.handler.component.HighlightComponent">
> <double name="time">0.0</double>
> </lst>
> <lst name="org.apache.solr.handler.component.StatsComponent">
> <double name="time">0.0</double>
> </lst>
> <lst name="org.apache.solr.handler.component.DebugComponent">
> <double name="time">0.0</double>
> </lst>
> </lst>
> <lst name="process">
> <double name="time">0.0</double>
> <lst name="org.apache.solr.handler.component.QueryComponent">
> <double name="time">0.0</double>
> </lst>
> <lst name="org.apache.solr.handler.component.FacetComponent">
> <double name="time">0.0</double>
> </lst>
> <lst name="org.apache.solr.handler.component.MoreLikeThisComponent">
> <double name="time">0.0</double>
> </lst>
> <lst name="org.apache.solr.handler.component.HighlightComponent">
> <double name="time">0.0</double>
> </lst>
> <lst name="org.apache.solr.handler.component.StatsComponent">
> <double name="time">0.0</double>
> </lst>
> <lst name="org.apache.solr.handler.component.DebugComponent">
> <double name="time">0.0</double>
> </lst>
> </lst>
> </lst>
> </lst>
> </response>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Strange-behavior-with-search-on-empty-string-and-NOT-tp3818023p3818023.html
> Sent from the Solr - User mailing list archive at Nabble.com.