我有一个带有 textacular gem 的 Rails (4.2.3) 博客应用程序,带有一个 Post
模型,该模型具有 title:string
和 body: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/