使用sunspot / solr搜索多个模型

时间:2011-12-22 13:07:35

标签: search model solr sunspot

我已经能够成功实现基本的全文搜索,但是当我尝试使用范围(“with statements”)时,任何涉及多对多关系模型的查询似乎都不适合我。我知道相关的行在db中,因为我的sql语句确实返回了数据。然而,太阳黑子查询不会返回任何结果...我敢肯定它可能是一个新手在我的结束... ...任何帮助将不胜感激...所以我们去... ...

我的模特

class User
    has_one :registration

    searchable do
        text  :first_name
        text  :last_name
        text  :email
    end
end

class Registration
    belongs_to    :user
    has_many    :registration_programs
    has_many    :programs, :through => :registration_programs     

    searchable do
        integer :user_id
        integer :registration_status_id
    end
end

class RegistrationProgram
    belongs_to :registration
    belongs     :program

    searchable do
        integer :registration_id
        integer :program_id
    end     
end

控制器中的我的查询

    @search = Sunspot.search(User, Registration, RegistrationPrograms)do

    # this works fine with the frame, lame, email fields "on its own"
    fulltext params["instructor-search"]

    any_of 
        all_of 
            with(:class => Registraion)
            with(:registration_status_id, 3)                             
        end

        all_of 
            with(:class => RegistraionProgram)
            with(:program_id, 1) 
        end
    end
end

数据库中有一些记录,其foo为f_name,其reg状态和程序字段为3和1个ID。但是我无法让Sunspot / websolr得到它们......我唯一一次让上述查询工作就是当我单独运行所有三个标准时......。每当我组合它们时,我似乎没有返回任何行。

非常感谢任何帮助/建议......

0 个答案:

没有答案
相关问题