简体   繁体   English

Solr查询具有字段的项目:值或根本没有字段值

[英]Solr query for items with field:value or no value for field at all

I'm trying to query Solr for entries that either have a certain value in a field OR no value for the field. 我正在尝试向Solr查询在字段中具有特定值或该字段没有值的条目。 The negated field value works when used by itself but causes the query to return no results when combined with anything else. 否定字段值在单独使用时有效,但会导致查询在与其他任何内容组合时不返回任何结果。 Below is a response with debugQuery enabled. 下面是启用debugQuery的响应。 The config file I use can be found here . 我使用的配置文件可以在这里找到。

<?xml version="1.0"?>
<response>
  <responseHeader>
    <status>0</status>
    <QTime>3</QTime>
    <lst name="params">
      <str name="facet">true</str>
      <str name="sort">sort_title asc</str>
      <str name="fl">id,nid,url,uid</str>
      <str name="debugQuery">true</str>
      <str name="facet.mincount">1</str>
      <str name="facet.sort">true</str>
      <str name="start">0</str>
      <str name="bf">recip(rord(created),4.000000,239,239)^200.000000</str>
      <arr name="fq">
        <str>NOT type:article</str>
        <str>NOT type:insect</str>
        <str>NOT type:news</str>
        <str>NOT type:plant</str>
        <str>im_cck_field_affected_plants:(20 OR -[* TO *])</str>
        <str>entity:node</str>
      </arr>
      <str name="version">1.2</str>
      <str name="rows">16</str>
    </lst>
  </responseHeader>
  <result name="response" numFound="0" start="0"/>
  <lst name="facet_counts">
    <lst name="facet_queries"/>
    <lst name="facet_fields"/>
    <lst name="facet_dates"/>
  </lst>
  <lst name="debug">
    <null name="rawquerystring"/>
    <null name="querystring"/>
    <str name="parsedquery">+MatchAllDocsQuery(*:*) FunctionQuery((239.0/(4.0*float(top(rord(created)))+239.0))^200.0)</str>
    <str name="parsedquery_toString">+*:* (239.0/(4.0*float(top(rord(created)))+239.0))^200.0</str>
    <lst name="explain"/>
    <str name="QParser">DisMaxQParser</str>
    <str name="altquerystring">org.apache.lucene.search.MatchAllDocsQuery:*:*</str>
    <arr name="boostfuncs">
      <str>recip(rord(created),4.000000,239,239)^200.000000</str>
    </arr>
    <arr name="filter_queries">
      <str>NOT type:article</str>
      <str>NOT type:insect</str>
      <str>NOT type:news</str>
      <str>NOT type:plant</str>
      <str>im_cck_field_affected_plants:(20 OR -[* TO *])</str>
      <str>entity:node</str>
    </arr>
    <arr name="parsed_filter_queries">
      <str>-type:article</str>
      <str>-type:insect</str>
      <str>-type:news</str>
      <str>-type:plant</str>
      <str>im_cck_field_affected_plants:20 -im_cck_field_affected_plants:[* TO *]</str>
      <str>entity:node</str>
    </arr>
    <lst name="timing">
      <double name="time">3.0</double>
      <lst name="prepare">
        <double name="time">3.0</double>
        <lst name="org.apache.solr.handler.component.QueryComponent">
          <double name="time">2.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.SpellCheckComponent">
          <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.SpellCheckComponent">
          <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>

Any help would be appreciated. 任何帮助,将不胜感激。

Finally phrased the question well enough to find an answer through Google. 最后说出这个问题,足以通过谷歌找到答案。

http://osdir.com/ml/solr-user.lucene.apache.org/2009-03/msg00480.html http://osdir.com/ml/solr-user.lucene.apache.org/2009-03/msg00480.html

OR NOT queries can be written as, using my case as an example: 或者不能将查询写成,以我的案例为例:

im_cck_field_affected_plants:20 OR (*:* -im_cck_field_affected_plants:[* TO *])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM