0

我将 Solr (3.6.0) 与 SolrNet (0.4) 一起使用,我正在寻找 SolrNet 中空间搜索的一些帮助 - 具体来说,按距离对结果进行排序。

这是我的查询:

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()

我还尝试将 lat、long 和 distance 参数传递给 geodist() 函数,但无济于事。

我可以手动构建这个查询,而不是通过 SolrNet!似乎问题与查询字符串的排序和括号的方式有关。

这有效(手工构建):

{d=1&sort=geodist()+asc&sfield=LatLong&version=2.2&rows=25&q=邮编:"LN1+2EB"&pt=52.1,-1.11&fq={!geofilt}}

这失败了(由 SolrNet 构建):

{d=1&sort=geodist()+asc&q=(邮编:"LN1+2EB")&sField=LatLong&pt=53.289186,-0.705095&fq={!geofilt}&rows=25&version=2.2}

我假设我在做一些愚蠢的事情;一定有办法让这个功能发挥作用!任何指针将不胜感激。

4

1 回答 1

1

这将按距离对结果进行排序。取消注释行以过滤从点的距离。

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
                                                                                        }
                                  });
于 2013-01-06T11:05:11.460 回答