代码之家  ›  专栏  ›  技术社区  ›  Tiago

rails pg_按大多数点击率搜索宝石顺序

  •  0
  • Tiago  · 技术社区  · 6 年前

    我有一个包含页面和标记的程序,我想添加 related pages 特色。

    规则是页面将根据它们共享的标签数量进行排名。

    所以:

    [
      { page: 'one', tags: ['a','b','c'] },
      { page: 'two', tags: ['a','b','c'] },
      { page: 'three', tags: ['a','b'] },
      { page: 'four', tags: ['a'] },
      { page: 'five', tags: ['z','w','y'] }
    ]
    

    与页相关的页的顺序 one 会是 ['two', 'three', 'four'] 是的。

    我创造了一个 pg_search_scope 如下所示

    class Tag
      has_many :pages
    end
    
    class Page
      has_many :tags
      pg_search_scope :search_tags,
        associated_against: { tags: :value },
        using: {
          tsearch: { any_word: true }
        }
    end
    

    所以我现在的问题是:我怎样才能得到 search_tags 是吗?

    0 回复  |  直到 6 年前
    推荐文章