2013-08-16 1 views
1

ActiveRecord 구문과 메소드를 Sunspot에서 제공 한 results 객체와 통합하는 방법이 있습니까?Rails Solr Sunspot과 ActiveRecord 통합

예를 들어, Post.where(...).search{fulltext 'pizza'}.results 모든 것을 색인없이 내 where(...) by 절 결과 및 Post.search{fulltext 'pizza'}.results.where(...) 반환 NoMethodError: undefined method 'where' for #<Sunspot::Search::PaginatedCollection:0x007fe9b388bd88>

를 필터링하지 않습니다, 액티브 쿼리 내 태양 흑점 검색을 조정하는 방법은 무엇입니까? 내 AR 필터 중 일부는 너무 복잡하여 Sunspot의 기본 구문으로 다시 작성하기가 쉽지 않습니다.

답변

0

아는 한 귀하의 조건문에 대한 필드를 색인화해야합니다.

Post.search do 
with(:blog_id, 1) 
fulltext("pizza") 
end 

지저분한 해결책은 결과를 검토 할 때 조건문을 추가하는 것입니다.

search.each_hit_with_result do |hit, result| 
    if result.post_id == 2 
    #stuff 
    end 
end 

또한 조건부 인덱스를 생성 할 수 있습니다. http://mikepackdev.com/blog_posts/19-conditional-indexing-with-sunspot