Searching across multiple models using sunspot/solr

半腔热情 提交于 2019-12-09 06:59:33

问题


I have been able to implement a basic full text search successfully, however any queries involving models from many to many relations don't seem to work for me when i try to use scopes ("with statements"). I know the relevant rows are in the db as my sql statements do return the data. however the sunspot queries don't return any results…i'm sure its probably a newbie goof up on my end…any assistance would be greatly appreciated…so here we go….

My Models

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

My Query in the Controller

    @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

There are records in the database that have foo as f_name and 3 and 1 ids for their reg status and program fields. however i can't get Sunspot/websolr to get them….the only time i have had the above query to work is when i run all the three criteria "individually"….! Whenever I combine them i don't seem to get any rows returned.

Any help/suggestions would be greatly appreciated…….

来源:https://stackoverflow.com/questions/8604294/searching-across-multiple-models-using-sunspot-solr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!