【问题标题】:Rails Sunspot Solr any_of with scalar field and fulltext search带有标量字段和全文搜索的 Rails Sunspot Solr any_of
【发布时间】:2015-03-13 21:46:30
【问题描述】:

我正在使用带有 sunspot solr 的 rails 4.0。我希望这样做:

(read_flag IS TRUE) OR ( (read_flag IS NIL) AND (fulltext params[:search] 为真))

这是我在(post.rb)中的代码:

@search =  Post.search do
  any_of
     with :model_id,params[:model_id]
     all_of
        with :model_id, nil
        fulltext params[:search] do
          fields(:title,:tags)
        end
     end
  end

end

但是,上面的代码会产生这个错误 undefined method 'fulltext' for #<Sunspot::DSL::Scope:0x007ff641ef2f38>

所以我尝试将all_of 更改为all。但它没有返回我想要的。

模型文件(post.rb)索引如下

  searchable do
    integer :user_id
    text :title, :boost => 2
    integer :model_id
  end  

谁能建议我应该如何构建我的查询?在 stackoverflow 上找不到任何相关问题。

【问题讨论】:

  • 有什么解决办法吗?

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


【解决方案1】:

我确定您可能很久以前就已经超越了这一点,因此为了任何可能发现此问题的人的利益,我一直在努力使用 any_of 和全文进行类似的搜索。我发现在全文似乎起作用之前结束了连接/分离:

@search =  Post.search do
  any_of
     with :model_id,params[:model_id]
     all_of
        with :model_id, nil
     end
  end
  fulltext params[:search] do
     fields(:title,:tags)
  end

end

【讨论】:

    猜你喜欢
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多