Conditions in Search

I have some data and I would like to do searches on them which would have conditions within them for example. I would like to search for Sports OR Crime and the result should be all pieces of data that include sports data and crime data. How could such a query be done.

Hello skelleex,

By default, Algolia will try to find results that match all your query words, meaning that your own query will return results for Sports AND Crime.

If all your records belong to one category such as Sports or Crime, I’d recommend you to use filters, as described here

However, if you’d like to perform disjunctive search for arbitrary words which may be found anywhere in your records, and not only in a specific field, filtering cannot be used. In this case, you should take a look at the search parameter named removeWordsIfNoResults This parameter, once configured to allOptional may retrieve results for any single word of your query, in case the original query returned no results at all in the first place.

I hope it helps.

Best regards,

The options you provided didn’t seem to work or it could be that I am missing what exactly you mean in your answer. I would try to explain better as to what I am looking for with Algolia.

When I do the query with no changes in configs (words used in the query are “sports, crime”) I get the result that has sports AND crime meaning both sports and crime needs to be in the data for it to be shown. What I want is that if I search for “sports, crime” that I see all data that has sports, all data that has crime and all data that includes both sports and crime.

Please note I am not looking within a specific category or property within my dataset but in all properties of my data object.

In that case, you should probably take a look at the optionalWords query parameter. It may have important impact on the perceived relevancy, depending on your dataset and your ranking.

Hey thanks this seems to be the option I need. Is there a way I can set all queries to be Optional Words so I can test it in the Dashboard?

No this is not possible, you need to specify it for every query.