Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algolia filter equivalent to SQL IN for arrays?

Tags:

algolia

I've got records in Algolia containing an array attribute with integer values, like :

{
  ...
  choice_ids: [1, 99, 100, 200]
  ...
}

I want to filter all records containing any value of another array. For example I search for [1, 300, 400, 600, 700], I should get the record on top because it contains 1.

Should I construct the filter with OR arguments or is there a better way?

like image 501
Nicolas Blanco Avatar asked Aug 27 '16 22:08

Nicolas Blanco


1 Answers

Should I construct the filter with OR arguments or is there a better way?

Yes that's the way to go.

index.search('....', { filters: '(choice_ids=1 OR choice_ids=99 OR choice_ids=100 OR choice_ids=200)' });
like image 140
redox Avatar answered Oct 30 '22 23:10

redox