ruby-on-rails - 使用 textacular gem,如何匹配大量文本中的一个词?

标签 ruby-on-rails postgresql full-text-search

我有一个带有 textacular gem 的 Rails (4.2.3) 博客应用程序,带有一个 Post 模型,该模型具有 title:stringbody:text.

我创建了一个帖子:

> my_post = Post.create! title: 'my post', body: 'this post is about physics and ...'

现在,我希望搜索“physics”以匹配 body ,但事实并非如此。如果我尝试:

> Post.basic_search('physics').first #=> nil

如果我将 body 变短,它会起作用:

> my_post.body = "about physics"
> my_post.save!
> Post.basic_search('physics').first #=> <my_post>

我也尝试过用 fuzzy_search 代替基本搜索,但结果相同。

如何使用 textacular 搜索长文本字段中是否存在单词?

最佳答案

Github 上的 README 说 Model.basic_search 将只搜索模型的 string 列:

Game.basic_search('Sonic') # will search through the model's :string columns
Game.basic_search(title: 'Mario', system: 'Nintendo')

对于模糊搜索,README 说:

Note that fuzzy searches are subject to a similarity threshold imposed by the pg_trgm module. The default is 0.3, meaning that at least 30% of the total string must match your search content.

您可以在大文本字段上将相似度阈值设置为非常小的值。

引用:Github

关于ruby-on-rails - 使用 textacular gem,如何匹配大量文本中的一个词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35730762/

相关文章:

ruby-on-rails - rails : remote_form_for not playing nicely with multiple submit_tags

ruby-on-rails - HTTPClient 从字符串发布

sql - 如何在 PostgreSQL 的 SELECT 语句中将行值用作列?

postgresql - Postgres JDBC 编号参数

mysql - 如何消除全文对结果数量的限制?

mongodb - 如何使用 MongoDB 搜索文档中所有字段的单词或字符串?

Django 和 PostgreSQL 全文搜索 : Some terms not found by search lookup

mysql - 我可以使用哪个网络服务器用于 ruby​​ on Rails 应用程序来承载大量数据

ruby-on-rails - 由 railsadmin 创建的 bool 字段在 mongoid 查询中被忽略

sql选择两者中最小值的记录