Lucene OR query not working

ⅰ亾dé卋堺 提交于 2019-12-23 23:15:09

问题


I am trying to query Solr with following requirement: _ I would like to get all documents which not have a particular field

-exclusivity:[* TO *]

  • I would like to get all document which have this field and got the specific value

exclusivity:(None)

so when I am trying to query Solr 4 with:

fq=(-exclusivity:[* TO *]) OR exclusivity:(None)

I have only got results if the field exists in document and the value is None but results not contain results from first query !!

I cannot understand why it is not working


回答1:


To explain your results, the query (-exclusivity:[* TO *]) will always get no results, because you haven't specified any result to retrieve. By default, Lucene doesn't retrieve any results, unless you tell it to get them. exclusivity:(None) isn't a limitation placed on the full result set, it is the key used to find the documents to retrieve. This differs from a database, which by default returns all records in a table, and allows you to limit the set.

(-exclusivity:[* TO *]) only specifies what NOT to get, but doesn't tell it to GET anything at all.

Solr has logic to handle Pure negative queries (I believe, in much the same way as below, by implicitly retrieving all documents first), but from what I gather, only as the top level query, and it does not handle queries like term1 OR -term2 documented here.

I believe with solr you should be able to use the query *:* to get all docs (though that would not be available in raw lucene), so you could use the query:

(*:* -exclusivity:[* TO *]) exclusivity:(None)

which would mean, get (all docs except those with a value in exclusivity) or docs where exclusivity = "None"




回答2:


I have founded answer to this problem. I have made bad assumption how "-" works in solr.I though that

-exclusivity:[* TO *]

add everything without exclusivity field to the data set but it is not the case. The '-' could only exclude things from data set. BTW femtoRgon you are right but I am using it as fq (filter query) not as a master query I have forgotten to mention that.

So the solution is like

-exclusivity:([* TO *] AND -(None))

and full query looks like

/?q=*:*&fq=-exclusivity:([* TO *] AND -(None))

so that means I will get everything does not have field exclusivity or has this field and it is populated with value None.



来源:https://stackoverflow.com/questions/14504616/lucene-or-query-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!