2013-06-03 1 views
0

다음과 같이 SOLR 검색을 수행합니다. Geohashes를 사용하는 lat/lng를 기반으로 데이터베이스에 몇 개의 위치를 ​​찾고 해당 위치에 제휴 링크가 있는지 확인하려고합니다. 테이블 Affiliates.Sunspot Solr 검색 - 'with'를 여러 개 사용하여 필터링하는 방법

search = Sunspot.search(opts[:types]) do 
    any_of do 
    0.upto(opts[:range]) do 
     geohash = GeoHash.encode(place.lat, place.lng, precision) 
     neighbors = GeoHash.neighbors(geohash) rescue [] 
     geohashes = [geohash] + neighbors 
     with(:affiliate_names, ['company_a', 'company_b']) 
     with(:"geohash_#{precision}", geohashes) 
     precision -= 1 
    end 
    end 
    without(:class, IgnoreClass) unless opts[:types].include?(VacationRental) 
end 
search.hits 

내가으로 실행하고 문제는이 검색이 affiliate_names 'company_a'와 'company_b'와 geohash와 장소에서 두 곳에서 끌어 것입니다. 특히,이 두 줄은 다음과 같습니다.

 with(:affiliate_names, ['company_a', 'company_b']) 
     with(:"geohash_#{precision}", geohashes) 

geohash 및 affiliate_name으로 필터링 할 위치를 원합니다. 지금은 성명서를 작성한 두 사람이 OR과 같이 행동합니다.

두 기준을 모두 충족하는 레코드를 가져 오기 위해 태양 흑점 검색을 수행하려면 어떻게해야합니까?

답변

1

알아 냈습니다. 당신은 둥지 코드를

all_of 
    with(:affiliate_names, ['company_a', 'company_b']) 
    with(:"geohash_#{precision}", geohashes) 
end 

이 보장됩니다 다음과 같이 할 수

당신이 맞는 두 요구 사항을 쿼리 SOLR 기록.