gpt4 book ai didi

mysql - 是否可以在动态条件下使用 Sphinx 搜索?

转载 作者:行者123 更新时间:2023-11-29 01:01:26 26 4
gpt4 key购买 nike

在我的网络应用程序中,我需要根据以下条件对 items 表执行 3 种类型的搜索:

  1. items.is_public = 1(使用title字段进行索引)-可以检索到很多结果(基数比其他情况高很多)

  2. items.category_id = {X}(使用 title + private_notes 字段进行索引)- 通常少于 100 个结果

  3. items.user_id = {X}(使用 title + private_notes 字段进行索引)- 通常少于 100 个结果

我找不到让 Sphinx 在所有这些情况下都能正常工作的方法,但在第一种情况下效果很好。我是否应该只在第一种情况下使用 Sphinx 并在 MySQL 中使用普通的“慢速”全文搜索(至少因为在 2-3 种情况下基数较低)?

还是只有我和 Sphinx 几乎可以做任何事情?

最佳答案

在不完全了解您的模型的情况下,我可能会遗漏一些东西,但这是怎么回事:

class item < ActiveRecord::Base
define_index do
indexes :title
indexes :private_notes
has :is_public, :type => :boolean
has :category_id
has :user_id
end
end

1)

Item.search(:conditions => {:title => "blah"}, :with => {:is_public => true})

2)

Item.search("blah", :with => {:category_id => 1})

3)

Item.search("blah", :with => {:user_id => 196})

关于mysql - 是否可以在动态条件下使用 Sphinx 搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2864429/

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