Tamil
Tamil

Reputation: 1203

Algolia not handle ORs of ANDs filter condition

Am using Algolia for search engine and I would like to fetch result from algolia as follows

  1. If visibility = everyone, then it will show to all users

  2. If visibility = private, then it will only for logged in user

To achieve that, i tried

filter="visibility:everyone" OR  ("visibility:me" AND "user.username:testuser")

But it return below error

{
  "message": "filters: filter (X AND Y) OR Z is not allowed, only (X OR Y) AND Z is allowed",
  "status": 400
}

How can i alter the condition to achieve above scenario?

Any help will appreciate and thank in advance.

Upvotes: 1

Views: 719

Answers (2)

Hadi R.
Hadi R.

Reputation: 403

try changing And Gate to OR Gate by two times implementing NOT for your case

NOT ("visibility:everyone" AND (NOT "visibility:me" OR NOT "user.username:testuser"))

Upvotes: 3

Jan Petr
Jan Petr

Reputation: 705

The condition can be simplified to

filter="visibility:everyone" OR "user.username:testuser"

which works with Algolia.

P.S. To make it more secure specify the filters directly to a secured API key and don't send it directly with a query.

Upvotes: 0

Related Questions