Search code examples
ruby-on-railsrubyelasticsearchactiverecordsearchkick

Is there a way to exclude words from a query in Searchkick?


I would like to exlude some terms a user may enter into the search bar as they bloat the results.

For separate reasons I need the operator: :or, but if I have a search term like "The Beatles" it searches the whole database for "The" and "Beatles" which is way too many results. I would like to exclude "the" from any query received, so it would be as if the user had only searched "Beatles".

Maybe this isn't possilbe. Thanks for the help 🙏

I tried to add exclude: ["the"], but this removed any ressults which had the term "the".


Solution

  • Did you tried it:

    "The Beatles".gsub('The ', '')