【问题标题】:how to rank records dynamically in a result set in rails using sunspot solr如何使用 sunspot solr 在 rails 的结果集中动态排列记录
【发布时间】:2015-06-03 11:42:01
【问题描述】:

我有users、cafes 和他们的food_items(列出了一些成分)。到目前为止,我使用 solr 通过用户喜欢的一些 ingredients 搜索 food_items。这是根据sunspot docs

使用 sunspot-solr 搜索完成的

另外,我能够收集到不同咖啡馆的用户的亲戚like-ness(基于他访问它的次数,搜索它的菜单等)(这是一个动态值,将即时生成)

问题: 我想显示通过 solr 获取的相同结果(food_items),排名咖啡馆(结果重新排名)(基于用户对咖啡馆的相似性)使用 sunspot solr for rails 此应用托管在 heroku 上,使用 websolr

我找到了这些:

https://cwiki.apache.org/confluence/display/solr/Query+Re-Ranking

https://cwiki.apache.org/confluence/display/solr/RankQuery+API

但我不知道如何创建QParserPlugin 或在太阳黑子中生成排名查询。

sunspot 提供了write custom queries 的方法。因此,如果我可以在构建查询以获取相似性并对每条记录(或)任何其他实现此类逻辑的方式进行排名时获得帮助,那就太好了。
谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby solr sunspot-solr websolr


    【解决方案1】:

    你可以这样做:-

    def build_query(where_conditions)
      condition_procs = where_conditions.map{|c| build_condition c}
    
      Sunspot.search(table_clazz) do
        condition_procs.each{|c| instance_eval &c}
        paginate(:page => page, :per_page => per_page)
      end
    end
    
    def build_condition(condition)
      Proc.new do
        # write this code as if it was inside the sunspot search block
        keywords condition['words'], :fields => condition[:field].to_sym
      end
    end
    
    conditions = [{words: "tasty pizza", field: "title"},
                  {words: "cheap",       field: "description"}]
    
    build_query conditions
    

    【讨论】:

    • 谢谢,但这是正常搜索。我希望重新排列生成的结果。请参考我提供的链接
    猜你喜欢
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多