So let's say I enter the text "Ebook" for searching and get the following results:
Ebook for Rails
Elastic Ebook
Booking for ebook.
Now I select "Elastic Ebook" from the list. Let's say that several other users input Ebook for searching and most of them select "Elastic Ebook" from the list. This clearly indicates the popularity for Elastic Ebook for the key word "Ebook". Hence in further searches, I would want Elastic Ebook to have higher priority and appear at the top.
Elastic Ebook
Ebook for Rails
Booking for an ebook.
Is there any way to achieve this.
My code document.rb :
require 'elasticsearch/model'
class Document < ApplicationRecord
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
belongs_to :user
Document.import force: true
def self.search(query)
__elasticsearch__.search({
query: {
multi_match: {
query: query,
fields: ['name^10', 'service'],
fuzziness: "AUTO"
}
}
})
end
settings index: {
"number_of_shards": 1,
analysis: {
analyzer: {
edge_ngram_analyzer: { type: "custom", tokenizer: "standard", filter:
["lowercase", "edge_ngram_filter", "stop", "kstem" ] },
}
},
filter: {
edge_ngram_filter: { type: "edgeNGram", min_gram: "3",
max_gram: "20" }
}
} do
mapping do
indexes :name, type: "string", analyzer: "edge_ngram_analyzer"
indexes :service, type: "string", analyzer: "edge_ngram_analyzer"
end
end
end
search controller code:
def search
if params[:query].nil?
@documents = []
else
@documents = Document.search params[:query]
end
end