Tag: edismax

太阳黑子`LIKE`查询

我正在使用sunspot 。 如何运行LIKE查询( LIKE %q% )? 我想做这样的事情: @search = Sunspot.search(User) do |q| q.text_fields { with(:company_name).like(params[:q]) } end.results 代替: @search = Sunspot.search(User) do |q| q.text_fields { with(:company_name).starting_with(params[:q]) } end.results 这部分对我有用。 回顾sunspot代码,我找到了这段代码: class StartingWith < Base private def to_solr_conditional "#{solr_value(@value)}*" end end 它基本上生成以下太阳黑子搜索哈希: Sunspot.search(User) do |q| q.text_fields { with(:company_name).starting_with(“sta”)} } end => Sunspot::Search:{:q=>”*:*”, :fq=>[“type:User”, “company_name_text:sta*”]} 如果没有更简单的方法来实现LIKE %query% […]