Reputation: 592
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>
Upvotes: 3
Views: 1584
Reputation: 592
After adding word_start to model
def autocomplete
book = Book.search(params[:term], limit: 10).map(&:title)
end
in controller, remove the fields
Upvotes: 2