ElasticSearch / Searchkick - LIKE query

I am using the ElasticSearch gem Searchkick with Rails and I want to perform a search based on two values:

- params[:full_text_query]
- params[:only_from_this_location]

      

You should search the full text in all fields, and the other should restrict the search to only records that partially match one field.

I need something like this:

Post.search(params[:full_text_query], where: { location: params[:only_from_this_location] })

      

However, I need a location filter so that it matches not only exact values ​​but also partial ones. So not only "New York", but also "New York, USA". Like% something% you would do in SQL.

I also need pagination support, so it has to be in one request.

What are my options?

+3


source to share


2 answers


Regular expressions are allowed for use inside Searchkick, where the. Try using something like this in your code.



Post.search(params[:full_text_query], where: { location: /.*#{params[:only_from_this_location]}.*/ })

      

+2


source


I am also struggling with such an issue in my current project, if you find anything to solve the LIKE query problem in searchckick please share.

However, in regards to pagination, you can add the following parameter to your string



Post.search(params[:full_text_query], where: { location: params[:only_from_this_location] }, per_page: 10)

      

0


source







All Articles