SolrNet结合SolrQueryByDistance和SolrQueryByField

时间:2013-01-05 16:52:19

标签: solr solrnet

我尝试以下方法:

Dim q = New SolrQueryByField("tag", keyword) With {.Quoted = False} Or New SolrQueryByField("cat", keyword) With {.Quoted = False} Or New SolrQueryByField("shortname", keyword) With {.Quoted = False}

Dim loc As New Location(latitude, longitude)
Dim qgeo = New SolrQueryByDistance("geo", loc, 10)

searchresults = solr.Query(q And qgeo).Cast(Of BusinessSolr)().ToList

从不起作用:

Value of type 'SolrNet.SolrQueryByDistance' cannot be converted to 'SolrNet.AbstractSolrQuery'.

(q和qgeo)

任何想法,关于如何组合fieldquery与距离? 如果可能的话,在VB.NET中。 Tks很多

btw:我使用Solr 4,SolrNet实际版本

1 个答案:

答案 0 :(得分:1)

我尝试重新创建您的方案并遇到同样的问题。在查看SolrQueryByDistance的源代码时,我发现它不是派生自AbstractSolrQuery类,而是导致此错误的原因。

您可以将距离查询用作Filter Query(将主查询的结果限制为仅包含给定距离内的项目)吗?如果是这样,您可以使用以下内容:

Dim q = New SolrQueryByField("tag", keyword) With {.Quoted = False} Or New SolrQueryByField("cat", keyword) With {.Quoted = False} Or New SolrQueryByField("shortname", keyword) With {.Quoted = False}

Dim loc As New Location(latitude, longitude)
Dim options = New QueryOptions() With { _
.FilterQueries = New ISolrQuery() {New SolrQueryByDistance("geo", loc, 10)} _
}

searchresults = solr.Query(q, options).Cast(Of BusinessSolr)().ToList