2012-07-19 48 views
0

我使用Solr(3.6.0)與SolrNet(0.4),我正在尋找一些與SolrNet空間搜索的幫助 - 具體地說,按距離排序結果。SolrNet空間搜索 - 排序geodist()

這裏是我的查詢:

var postcode = new SolrQueryByField("Postcode", fields[13]); 
var distance = new SolrQueryByDistance("LatLong", latitude, longitude, 1); 
QueryOptions options = new QueryOptions(); 
options.Rows = 25; 
options.AddFilterQueries(distance); 

我已經嘗試了明顯的事情:

options.OrderBy = new List<SortOrder> { new SortOrder("geodist()", Order.ASC)}; 

和:

options.OrderBy = new List<SortOrder> { SortOrder.Parse("geodist() asc") }; 

,並作爲最後努力,我試過定義過濾器查詢與排序一起作爲額外參數:

options.ExtraParams = new Dictionary<string, string> 
{ 
    {"d", "1"},       
    {"sField", "LatLong"}, 
    {"pt", latitudeString + "," + longitudeString}, 
    {"fq", "{!geofilt}"}, 
    {"sort", "geodist() asc"} 
}; 

但一切結果:

SEVERE: org.apache.solr.common.SolrException: can not sort on unindexed field: geodist() 

我也試過路過的緯度,經度和距離參數的geodist()函數,都無濟於事。

我能夠通過手工構建這個查詢,而不是通過SolrNet!這似乎是問題與查詢字符串的排序方式和方括號。

這工作(手工構造):

{d = 1 &排序= geodist()+ ASC &元數= LatLong網&版本= 2.2 &行= 25 & Q =郵編: 「LN1 + 2EB」 & PT = 52.1,-1.11 & FQ =}

此失敗(由SolrNet構造){geofilt!}:

{d = 1 &排序= geodist()+ ASC & q =(郵編: 「LN1 + 2EB」)&元數= LatLong網& PT = 53.289186,-0.705095 & FQ = &行= 25 &版本= 2.2}

我認爲我在做一些愚蠢的; {geofilt!}必須有一種方法可以使這個功能起作用!任何指針將不勝感激。

+0

https://groups.google.com/forum/#!forum/solrnet – 2012-07-19 23:00:20

回答

0

這將按距離排序結果。取消對線條的註釋也可以按照距離點的距離進行過濾。

solr.Query(SolrQuery.All, 
           new QueryOptions 
            { 
             FilterQueries = filterQueries.ToArray(), // add filter items 
             OrderBy = new[] { new SolrNet.SortOrder("geodist()", Order.ASC) }, 
             ExtraParams = new Dictionary<string, string> 
              { 
               // uncomment for filtering by distance 
               //{"fq", "{!geofilt}"}, 
               //{"d", distance.ToString(CultureInfo.InvariantCulture)} replace distance with your radius filter 
               {"sfield", "lat_long"}, // replace lat_long with your field in solr that stores the lat long values 
               {"pt", "-33.858727,151.213199"}, // this is the point of reference 
                         } 
            });