【问题标题】:Is there a way with Solr to search fuzzy AND exact?Solr 有没有办法搜索模糊和精确?
【发布时间】:2012-10-22 16:40:08
【问题描述】:

感谢您抽出宝贵时间

问题

我在基于模糊名称搜索和精确区域搜索来搜索记录时遇到问题。这就是我现在拥有的:

我现在拥有的

# :klantnaam is a param from a search-form
@param = Staffingcustomer.search do
    fulltext params[:klantnaam]
end
@staffingcustomers = @param.results

还有另一个字段,“区域”。
结果应该只包含某个“区域”。

示例要求

例如,
我是 Regio 3 的用户。 我想使用模糊名称搜索 Anne 和我自己的 Regio 3 可视化/选择所有 Staffingcustomers。所以,我不想看到带有 Regio 2 的 Staffingcustomers。

现在发生的是:

@param = Staffingcustomer.search do
     fulltext 'anne'
end
@staffingcustomers = @param.results

将返回所有不同区域的所有 Staffingcustomers...

经过一些研究/逻辑思考

我认为可能是这样的:

@param = Staffingcustomer.search do
    fulltext params[:klantnaam]
end
@staffingcustomers = @param.results.find(:all, :conditions => {:regio => 3})

或

@param = Staffingcustomer.search do
    fulltext params[:klantnaam] and fulltext '3'   ## or 3, without the quotes
end
@staffingcustomers = @param.results

但这似乎不起作用。

你能帮我解决这个问题吗?

逻辑问题

实际上,这是对一个巨大表的“精确选择”部分的模糊搜索。

希望你能帮忙。

提前致谢。

Kers。

【问题讨论】:

标签: ruby-on-rails-3 solr sunspot-rails fuzzy-search exact-match


【解决方案1】:

我想你想要这样的东西:

# find Staffing Customers with Regio 3 and text of params[:klantnaam]
@param = Staffingcustomer.search do
  with(:regio, 3)
  fulltext params[:klantnaam]
end
@staffingcustomers = @param.results

请参阅https://github.com/sunspot/sunspot#readme。您还必须将 Staffingcustomer 模型的 Searchable 块中的区域索引为您存储在数据库中的任何数据类型(例如整数)。

【讨论】:

  • 谢谢,这确实应该这样做。我还没有测试它,因为我想出了一个办法。首先,我选择了 :regio => 3 的所有 Staffingcustomers,然后我对其进行了模糊搜索。这样可行。但再次感谢,感谢您的推荐。
猜你喜欢
  • 1970-01-01
  • 2021-03-27
  • 2010-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-07
相关资源
最近更新 更多