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

时间:2010-08-06 02:39:02

标签: drupal solr

我正在尝试向Solr查询在字段中具有特定值或该字段没有值的条目。否定字段值在单独使用时有效,但会导致查询在与其他任何内容组合时不返回任何结果。下面是启用debugQuery的响应。我使用的配置文件可以找到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>

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:15)

最后通过谷歌找到了答案。

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

OR NOT查询可以写成,以我的案例为例:

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