gpt4 book ai didi

mysql - Thinking Sphinx - 搜索博客文章的标题、内容和标签

转载 作者:行者123 更新时间:2023-11-29 23:07:43 25 4
gpt4 key购买 nike

我正在尝试更新博客文章的搜索功能,用于搜索标题、内容和标签。目前,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 如何与其集成:插入/更新不会自动添加到您的 Sphinx 索引文件中。

因此,如果您希望搜索结果准确,则需要定期运行 ts:index rake 任务。

注释中提到的

ts:rebuild 会停止 Sphinx,然后运行 ​​ts:index,然后再次启动 Sphinx - 但如果您不更改结构你的索引(只是数据),那么就不需要 Sphinx 停止/启动。它有点像 db:migrate 的等价物。最好坚持使用 ts:index 来执行计划任务。

关于mysql - Thinking Sphinx - 搜索博客文章的标题、内容和标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28222589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com