Solr过滤器查询可能为空的多值字段

时间:2018-04-10 17:12:56

标签: solr

我的每个索引文档都有一个多值字段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的文档集?

我可以使用Page 1

获取fq=!user_ids_ims:[* TO *]

我可以使用Thing 2

获取fq=user_ids_ims:(42)

2 个答案:

答案 0 :(得分:1)

The actual answer is that you combine the two requirements:

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

The latter *:* is important, since you have to have a set of documents to subtract the set returned by user_ids_ims:[* TO *] from. This will give you any documents that have 42 in the field, or do not have the field at all.

答案 1 :(得分:0)

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

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

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

相关问题