小编ozi*_*ind的帖子

使用sunspot/solr搜索多个模型

我已经能够成功地实现基本的全文搜索,但是当我尝试使用范围("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
Run Code Online (Sandbox Code Playgroud)

我在控制器中的查询

    @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 …
Run Code Online (Sandbox Code Playgroud)

search solr model sunspot

5
推荐指数
0
解决办法
899
查看次数

标签 统计

model ×1

search ×1

solr ×1

sunspot ×1