1
votes

Each of my indexed documents has a multi valued field user_ids_ims that contains user ids to which the document is related. This field may be empty.

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

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

I want a filter query for all the documents where user_ids_ims contains a particular id value, say 42, or is empty. e.g. for the following documents:

{ 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] }

How do I use fq to include the set of documents including Page 1 and Thing 2?

I can get Page 1 using fq=!user_ids_ims:[* TO *]

I can get Thing 2 using fq=user_ids_ims:(42)

2

2 Answers

3
votes

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.

0
votes

The user_ids_ims field is populated using values from a MySQL column defined with AUTO_INCREMENT, so I know that 0 is not a valid id. With this knowledge, I can assign:

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

Now I have 2 defined values to search for, which is just fine, i.e. fq=user_ids_ims:(0 42)