【发布时间】: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