Thinking Sphinx - 搜索博客文章的标题、内容和标签
Thinking Sphinx - search title, content and tags of blog posts
我正在尝试更新搜索标题、内容和标签的博文搜索功能。现在,Thinking Sphinx 并未搜索标签。它正在执行以下查询:
SELECT * FROM `blog_post_core` WHERE MATCH('vacation')
如何让搜索包含标签?下面是索引文件。
ThinkingSphinx::Index.define 'blog/post', with: :active_record do
indexes :title
indexes :content
indexes "replace(tag_cache, '#{TAG_SEPARATOR}', ' ')", as: :tag_name
indexes user.username, as: :author
has :created_at
end
编辑: TAG_SEPARATOR 是一个类似“!!!”的字符串。 tag_cache是一个包含所有标签的字符串,但是是分开的,比如"vacation!!!work"。替换实际上获得了 :tag_cache 属性并将其拆分为多个标签吗?
也许您知道这一点,但如果没有:关于 Sphinx 的事情以及 Thinking Sphinx 如何与之集成:inserts/updates 不会自动添加到您的 Sphinx 索引文件中。
因此,如果您希望搜索结果准确,您需要定期 运行 ts:index
rake 任务。
ts:rebuild
,在评论中提到,停止 Sphinx,然后 运行s ts:index
,然后再次启动 Sphinx - 但如果你没有改变索引的结构(只是数据),那么就不需要 Sphinx stop/start。这有点像 db:migrate
的等价物。最好坚持 ts:index
计划任务。
我正在尝试更新搜索标题、内容和标签的博文搜索功能。现在,Thinking Sphinx 并未搜索标签。它正在执行以下查询:
SELECT * FROM `blog_post_core` WHERE MATCH('vacation')
如何让搜索包含标签?下面是索引文件。
ThinkingSphinx::Index.define 'blog/post', with: :active_record do
indexes :title
indexes :content
indexes "replace(tag_cache, '#{TAG_SEPARATOR}', ' ')", as: :tag_name
indexes user.username, as: :author
has :created_at
end
编辑: TAG_SEPARATOR 是一个类似“!!!”的字符串。 tag_cache是一个包含所有标签的字符串,但是是分开的,比如"vacation!!!work"。替换实际上获得了 :tag_cache 属性并将其拆分为多个标签吗?
也许您知道这一点,但如果没有:关于 Sphinx 的事情以及 Thinking Sphinx 如何与之集成:inserts/updates 不会自动添加到您的 Sphinx 索引文件中。
因此,如果您希望搜索结果准确,您需要定期 运行 ts:index
rake 任务。
ts:rebuild
,在评论中提到,停止 Sphinx,然后 运行s ts:index
,然后再次启动 Sphinx - 但如果你没有改变索引的结构(只是数据),那么就不需要 Sphinx stop/start。这有点像 db:migrate
的等价物。最好坚持 ts:index
计划任务。