Search code examples
ruby-on-railselasticsearchsearchkick

Searchkick word_start not working in Rails


Searchkick autocomplete works perfectly with text_start, but word_start doesn't do what it's supposed to do regarding finding a word within a body of text.

Model:

class Book < ActiveRecord::Base
      searchkick word_start: [:title, :description]

Controller:

def autocomplete
 book = Book.search(params[:term], fields: [{title: :word_start}, {description: :word_start}], limit: 10).map(&:title)
end

Am I missing something?

Here's the Script for autocomplete

<script>
 $("#query").autocomplete({
   source: "/searches/autocomplete",
   minLength: 2
 });
</script>

Solution

  • After adding word_start to model

    def autocomplete
     book = Book.search(params[:term], limit: 10).map(&:title)
    end
    

    in controller, remove the fields