Reputation: 1
I want to boost documents in the result based on any text field.
eg. consider following schema
class Post < ActiveRecord::Base
searchable do
text :title, :body
text :comments do
comments.map { |comment| comment.body }
end
text :tags
boolean :featured
end
end
to boost on the Boolean field we can simple add a boost clause like this:
Post.search do
fulltext '*:*' do
boost(2.0){with(:featured, true)}
end
end
I want to achieve boosting on text field, let's say I want to get all the post, but post tagged 'important' must come first, something like this:
Post.search do
fulltext '*:*' do
boost(2.0){fulltext 'important', fields: :tags}
end
end
I know above code is not correct, but explains the required behaviour.
Upvotes: 0
Views: 138
Reputation: 1152
Try this
Post.search do
fulltext '*:*' do
boost(2) { with(:tags).equal_to('important') }
end
end
Upvotes: 0