On rails 4 with the acts as taggable gem. My search is currently not returning exact matches first. It seems to be like the tags aren't being weighted properly. When I get rid of the :associated_against => { :tags => {:name => 'D'}}
exact matches are returned first. Has anyone ran into this issue before? Any suggestions?
Here is my search scope:
pg_search_scope :search, :against => { :specific => 'A', :title => 'B', :aka => 'B'},
:associated_against => { :tags => {:name => 'D'}},
:using => { dmetaphone: {}, tsearch: { dictionary: 'english' },
trigram: {:threshold => 0.3} },
ignoring: :accents
Can you post the rest of your code in the controller, etc. I have the following in my app:
# tools.rb
include PgSearch
pg_search_scope :search_including_tags,
:against => [:description, :barcode],
:associated_against => {:tags => [:name] }
Then in my controller to search through I have:
#tools_controller.rb
def index
if params[:search]
@tools = Tool.where("(barcode) LIKE (?)", "%#{params[:search]}")
elsif params[:tag]
@tools = Tool.tagged_with(params[:tag])
elsif params[:id]
@tool = Tool.find(params[:id])
else
@tools = Tool.all
@tool = Tool.first
end
end
and finally for my search controller
def new
@tools = Tool.search_including_tags(params[:query])
end
Hope this helps. Can't really say much without seeing all of the code. But I ended up using this which worked: :associated_against => {:tags => [:name] }
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.