简体   繁体   中英

Rails Elasticsearch + Searchkick

I have a problem with integrating searchkick and elasticsearch. Here is what I have as of now:

Product records:
id: 1
title: "Electric Fan"

id: 2
title: "Stove"

id: 3
title: "Stoven"

id: 4
title: "Stovener"

Here is my model

class Product < ActiveRecord::Base
  searchkick
end

But when I go to the rails console and try to search it only gives me one result:

results = Product.search("Stove")
results.map(&:title) # prints ["Stove"]

I don't know why it is only generating one results which in fact it should generate three. I installed and made sure that elasticsearch is running.

Is there anything that I missed with this one?

TIA

Read the documentation:

By default, results must match the entire word - back will not match backpack. You can change this behavior with:

class Product < ActiveRecord::Base
  searchkick word_start: [:name]
end

And to search (after you reindex):

Product.search "back", fields: [{name: :word_start}]

SOURCE - https://github.com/ankane/searchkick#partial-matches

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM