How to perform an A OR ( B AND C ) filter/facet match?

The objects are like this:

{
  usertype: 'person', // acceptable values are 'person', 'organization', and 'entity'
  data: {
    name: 'john doe',
    ...
  },
  isComplete: false, // computed at index time
},
{
  usertype: 'entity', // acceptable values are 'person', 'organization', and 'entity'
  data: {
    name: 'ibm',
    ...
  },
  isComplete: true, // computed at index time
},
{
  usertype: 'organization', // acceptable values are 'person', 'organization', and 'entity'
  data: {
    name: 'red cross',
    ...
  },
  isComplete: false, // computed at index time
}

I want a filter to match:

  • all objects that are NOT usertype:person
  • for objects that are usertype: person , isComplete must be true. In other words, (usertype:person AND isComplete:true)

This means the full filter should be: (usertype:person AND isComplete:true) OR NOT usertype:person , which has the form A OR ( B AND C ) . The problem here is that Algolia doesn’t allow this type of filter for performance reasons.

Any suggestions/solutions for achieving such a filter? Thanks!

Hi!

One solution would be to compute an extra attribute isCompletePerson at index time, taking the boolean value of B AND C to remove the nesting of your boolean computation at query time.

Regards,