2010-05-19 43 views
1

在我的web应用程序,我需要执行与以下条件对items表检索的3种类型:有没有可能在动态条件下使用Sphinx搜索?

  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仅仅用于第一种情况,并在MySQL中使用普通的“慢”FULLTEXT搜索(至少是因为2-3例中的低基数)?

还是只是我和狮身人面像可以做几乎所有的东西?

回答

1

没有你的模型,我可能失去了一些东西的全面了解,但怎么就是:

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}) 
+0

谢谢!我发现think_sphinx比Ultrasphinx宝石更强大。所以现在不需要切换回非狮身人面像FULLTEXT搜索。 – ep3static 2010-05-20 05:29:37