如何使用 Searchkick 匹配 Elasticsearch 中不完整的术语?
How to match incomplete terms in Elasticsearch using Searchkick?
我在 Rails 应用程序中使用 Elasticsearch + Searchkick 来索引文章。当我使用不完整的词进行搜索时,它不起作用。例如:
Article.search('feature compatibility').pluck(:name)
# => ["Feature compatibility by mobile device"]
Article.search('feature compatibil').pluck(:name)
# => []
我的模型使用默认的 Searchkick 设置。
首先将其添加到您的模型中(word_start
而不是 text_start
)
searchkick word_start: [:name, :body]
然后您需要删除索引,重新创建它并重新索引您的数据。
之后您的搜索查询将按预期工作
我在 Rails 应用程序中使用 Elasticsearch + Searchkick 来索引文章。当我使用不完整的词进行搜索时,它不起作用。例如:
Article.search('feature compatibility').pluck(:name)
# => ["Feature compatibility by mobile device"]
Article.search('feature compatibil').pluck(:name)
# => []
我的模型使用默认的 Searchkick 设置。
首先将其添加到您的模型中(word_start
而不是 text_start
)
searchkick word_start: [:name, :body]
然后您需要删除索引,重新创建它并重新索引您的数据。 之后您的搜索查询将按预期工作