【问题标题】:Solr filter query on multi valued field that may be emptySolr过滤查询可能为空的多值字段
【发布时间】:2018-04-10 17:12:55
【问题描述】:

我的每个索引文档都有一个多值字段user_ids_ims,其中包含与文档相关的用户 ID。此字段可能为空。

<types>
  <fieldType name="tint" class="solr.IntPointField" omitNorms="true"/>
</types>

<fields>
  <dynamicField name="*_ims" type="tint" multiValued="true"/>
</fields>

我想要对 user_ids_ims 包含特定 id 值(例如 42)或为空的所有文档进行过滤查询。例如对于以下文件:

{ id: 'Page 1', user_ids_ims: [] }
{ id: 'Thing 1', user_ids_ims: [19, 24, 92] }
{ id: 'Thing 2', user_ids_ims: [19, 24, 42, 92] }
{ id: 'Thing 7', user_ids_ims: [19, 24, 92] }

如何使用fq 包含Page 1Thing 2 等文档集?

我可以使用fq=!user_ids_ims:[* TO *] 获得Page 1

我可以使用fq=user_ids_ims:(42)获得Thing 2

【问题讨论】:

    标签: solr


    【解决方案1】:

    实际的答案是你把这两个要求结合起来:

    fq=user_ids_ims:(42) OR (*:* -user_ids_ims:[* TO *])
    

    后者*:* 很重要,因为您必须有一组文档才能从中减去user_ids_ims:[* TO *] 返回的集合。这将为您提供字段中包含 42 或根本没有字段的任何文档。

    【讨论】:

      【解决方案2】:

      user_ids_ims 字段是使用AUTO_INCREMENT 定义的 MySQL 列中的值填充的,所以我知道0 不是有效的id。有了这些知识,我可以分配:

      { id: 'Page 1', user_ids_ims: [0] }
      

      现在我有 2 个定义的值要搜索,这很好,即fq=user_ids_ims:(0 42)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-01-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-13
        • 1970-01-01
        相关资源
        最近更新 更多