tranthaihoang
tranthaihoang

Reputation: 491

How to query Solr apache php array one value

I have data

id = [1,2,3]
id = [2]
id = [2,3]
id = [1,3]
id = [2]

Expected results:

id = [2]
id = [2]

Current results:

id = [1,2,3]
id = [2]
id = [2,3]
id = [2]

My current query:

$query->createFilterQuery('id')->setQuery('id:2');

I just want to get arrays that have one value, and it will be equal to the value I passed in like 1 or 2 or 3. As in the above example, I pass the value = 3, the result will return null.

Thank everyone!

Upvotes: 1

Views: 204

Answers (1)

MatsLindh
MatsLindh

Reputation: 52832

You can use a query like id:2 AND NOT id:[* TO 2} AND NOT id:{2 TO *]. It'll effectively search for any documents that have 2 in the id field, and then remove any documents that have any value less than or more than the desired id value.

The difference between { and [ is that one is exclusive and the other is inclusive of the value itself.

Upvotes: 1

Related Questions