0

I have a filter query to return all the records matching an id in a field

$query->createFilterQuery('categoryId')->setQuery(
  sprintf('categoryId:(%s)', implode(' OR ', $categoryId))
);

this works. But how can I match everything that doesn't have that id? I need to replace OR with AND

$query->createFilterQuery('categoryId')->setQuery(
  sprintf('!categoryId:(%s)', implode(' AND ', $categoryId))
);

but I don't know how to tell SOLR to exclude those ids?

user3174311
  • 1,714
  • 5
  • 28
  • 66
  • 1
    `*:* -categoryId:(123 OR 456 OR 789)` - you generally don't need to replace OR with AND inside the `categoryId`, as that would require a document to have ALL the ids to be excluded, and not to exclude any document that resides in either of the categories (.. so it depends on what you want to achieve) – MatsLindh Feb 28 '23 at 12:00
  • yes I would like to exclude them. What I am trying to achieve is to have an option like (mysql equivalent) WHERE id = 1 OR id = 2 OR id = 3, and another option like WHERE id <> 1 AND id <> 2 AND id <> 3 – user3174311 Feb 28 '23 at 12:09
  • 1
    In that case the query as given above should work, it'll exclude any docouments that are in category 123, 456 _or_ 789. – MatsLindh Feb 28 '23 at 12:19

0 Answers0