2013-06-03 68 views
0

我有以下SOLR搜索,我試圖找到我的數據庫中的幾個地方根據lat/lng使用Geohashes並確保這些地方有一個會員鏈接通過Affiliates表。太陽黑子Solr搜索 - 如何過濾多個'與'

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」內這兩個地方拉。具體來說,這兩行:

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

我想通過geohash和affiliate_name過濾地點。現在,這兩個聲明就像一個OR。

我該如何做一個Solr太陽黑搜索來提取符合條件的記錄?

回答

1

我想通了。

可以嵌套的代碼如下

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

這將確保您查詢千篇一律都要求Solr的記錄。