Stefan Wuthrich
Stefan Wuthrich

Reputation: 47

SolrNet Combine SolrQueryByDistance and SolrQueryByField

I try the following:

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

Which dont work as of:

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

(q and qgeo)

Any idea, on how to do a combination of a fieldquery with a distance ? If possible in VB.NET. Tks a lot

btw: I use Solr 4, SolrNet actual version

Upvotes: 1

Views: 864

Answers (1)

Paige Cook
Paige Cook

Reputation: 22555

I tried to recreate your scenario and experienced the same issue. In looking at the source code for SolrQueryByDistance, I see that it does not derive from the AbstractSolrQuery class and that is reason for this error.

Could you use the Distance query as a Filter Query (limiting the results of the main query to only those items that are within the given distance)? If so, you can use the following:

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 

Upvotes: 1

Related Questions