Reputation: 2740
In my project I want to boost a search result of PersonRecord if the user_id matches. Each PersonRecord has an array of user_ids(those users own that PersonRecord). Now I want to pass a name and user_id to the search, and want to return an exact match with name, and boost the search result if there's a match in user_id. Here's the code:
results = PersonRecord.search do |search|
search.query do |query|
query.boolean do |m|
m.must {match 'name.full', 'David Butler'}
m.should {|m| m.term 'user_ids', user.id, :boost => 100}
end
end
end
Note here user_ids is the array of user_id and user.id is string. Should I use term here in the query, Or Ids? Or match? Any suggestions? Does term compare array to a string? Thanks.
Upvotes: 1
Views: 1230
Reputation: 66
You can use terms for this
m.should { m.terms 'user_ids', [user ids array], :boost => 100}
Upvotes: 2