简体   繁体   English

Rails:如何使用PG_Search搜索Act_As_Taggable_On生成的标签? (PostgreSQL系统)

[英]Rails: How do I search tags generated by Act_As_Taggable_On with PG_Search? (postgresql)

I am currently using Act_as_taggable_on for tagging and pg_search to search through my postgresql database on my Rails 3 application. 我目前使用Act_as_taggable_on标记和pg_search通过我的PostgreSQL数据库我的Rails搜索3应用程序。

How would I search through tags generated by the act_as_taggable_on gem with pg_search? 如何使用pg_search搜索act_as_taggable_on gem生成的标签? I can view the tags of a Post by saying "Post.find(1).tag_list," but there are no "tag" columns in the Post table, so when I run the 我可以通过说“Post.find(1).tag_list”来查看帖子的标签,但Post表中没有“tag”列,所以当我运行时

 pg_search_scope :search_by_weight, :against => {:tag_list => 'A', :title => 'B', :content => 'C'} #,:using => [:tsearch => {:prefix => true}] #:trigram, :dmetaphone]

it gives me an error because the column Post.tag_list doesn't exist in the Post table. 它给了我一个错误,因为Post表中没有Post.tag_list列。 What is it called when you can find the value through the dot connector (ie mission.tag_list) but when it doesn't exist in the table? 当你可以通过点连接器(即mission.tag_list)找到值但表中不存在时,它叫什么? I didn't know what to type. 我不知道要输入什么。 So basically, how do I pass in a non-existent column as a params? 基本上,我如何将不存在的列作为参数传入?

Also, you may have noticed I commented out the 另外,你可能已经注意到我已经注释掉了

 :using => [:tsearch => {:prefix => true}] #:trigram, :dmetaphone]

above. 以上。 I can't seem to find how to install extra modules for Postgresql. 我似乎无法找到如何为Postgresql安装额外的模块。 Where do I type CREATE EXTENSION? 我在哪里输入CREATE EXTENSION? (using ubuntu 11.10 and postgresql 9.1.3 -> and heroku for production) (使用ubuntu 11.10和postgresql 9.1.3 - >和heroku进行制作)

A much more simple approach is just using the association and search that through pg_search which is done like this: 一个更简单的方法是使用通过pg_search的关联和搜索,这样做:

class Item < ActiveRecord::Base
 include PgSearch  

  pg_search_scope :full_search, 
    :against => {  
    :item_status => 'A',
    :title => 'B',
    :description => 'C'    
   },       
    :associated_against => {
    :tags => [:name]    
   }
end 

I just implemented this in one of my projects and it worked well (searched through tag names). 我刚刚在我的一个项目中实现了它并且运行良好(通过标记名称搜索)。 Unfortunately I can't figure out how to weight an associated relationship since it says "tags" column not found in Items table. 不幸的是,我无法弄清楚如何对关联关系进行加权,因为它在项目表中找不到“标签”列。

This worked for me to get the tags weighted as well 这对我来说也可以加权标签

    pg_search_scope :search_by_weight, 
      :against => {  
      :title => 'B',
      :content => 'C'    
    },       
    :associated_against => {
      :tags => { :name => 'A' }    
    },
    using: {tsearch: {dictionary: "english"}}

I wrote my implementation in plpgsql a few years ago. 几年前我在plpgsql中编写了我的实现。 See my blog: http://omarqureshi.net/articles/2010-12-25-tsearch2-for-rails-applications which covers how to get it working. 请参阅我的博客: http//omarqureshi.net/articles/2010-12-25-tsearch2-for-rails-applications ,其中介绍了如何使其正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM