Use synonims with filter

I have multiple documents as shown below with _tags.

{
  "id": "5b28b701fe9cb70d08003444",
  "type": "Resort",
  "city": "Colombo",
  "country": "Sri Lanka",
  "_geoloc": {
    "lat": "7.0908481",
    "lng": "79.95546760000002"
  },
  "_tags": [
    "clouds",
    "food",
    "nature",
    "relaxing"
  ]
}

I want to search only from _tag field where i have declared synonyms for each _tag. But when i filter document with given synonym for tag, search results are empty.

I have read somewhere that synonyms doesn’t support with filters . So i’m planning to make full text multiple search queries including each user entered tag with the each query as shown below.

$queries = [
  [
    'indexName' => 'accommodation',
    'query' => *user_entered_tag*
  ],
  [
    'indexName' => 'accommodation',
    'query' => *user_entered_tag*
  ],
  [
    'indexName' => 'accommodation',
    'query' => *user_entered_tag*
  ]
];

The reason i’m going to use multiple queries is, if i send entire user entered text with single query even it includes synonyms that i have declared before, it doesn’t match any record. Because algolia tries to match entire text with my document which in this scenario i don’t want.

Do I have any workaround apart from this solution…?

Hi,

I am not fully sure to understand all of your needs here especially regarding searching vs filtering.

Some remarks that may help:

  • by default, _tags are not considered as searchableAttributes so if you want that the search query matches the content of your _tags, you’ll need to define _tags as part of the searchableAttributes;
  • if you add _tags in the searchable attributes, the synonyms will work for the search query;
  • the synonyms will never work when filtering meaning that if you use the _tags for filtering and not searching, then synonyms will not work;
  • by default, Algolia will try to match all words from the search query (not that we do not match the exact search sentence but will match all search words separately); optionalWords is a way to match any word instead of all of them.

I hope this helps. Please let us know if you need more details.