How to add Spatial Solr to Solrnet request

I am running Solr on my Windows machine using a jetty. I downloaded the Spatial Solr Plugin , which I finally managed to launch and run. I also use Solrnet to request Solr from my asp.net mvc project.

Now adding data to my index seems to work fine, and SpatialTierUpdateProcessorFactory also works.

The problem is this:

How to add a spatial query to my regular queries using the Solrnet library. I tried adding it using the "ExtraParams" parameter, but that didn't work.

Here is an example of how I am trying to combine a spatial query with a data range query. A date range query works fine without a spatial query attached to it:

new SolrQuery("{!spatial lat=51.5224 long=-2.6257 radius=10000 unit=km calc=arc threadCount=2}") && new SolrQuery(MyCustomQuery.Query) && new SolrQuery(DateRangeQuery);

which leads to the following query regarding Solr:

(({!spatial lat=51.5224 long=-2.6257 radius=100 unit=km calc=arc threadCount=2} AND *:*) AND _date:[2010-05-07T13:13:37Z TO 2011-05-07T13:13:37Z])

And the error message appears:

The remote server returned an error: (400) Bad request.

SEVERE: org.apache.solr.common.SolrException: org.apache.lucene.queryParser.Pars
eException: Cannot parse '(({!spatial lat=51.5224 lng=-2.6257 radius=10000 unit=
km calc=arc threadCount=2} AND *:*) AND _date:[2010-05-07T13:09:49Z TO 2011-05-0
7T13:09:49Z])': Encountered " <RANGEEX_GOOP> "lng=-2.6257 "" at line 1, column 2
4.
Was expecting:
    "}" ...

Now, if I use the Solr Web Admin administration page and run the following request against it, everything works fine.

{!spatial lat=50.8371 long=4.35536 radius=100 calc=arc unit=km threadcount=2}text:London

What is the best / right way to call a spatial function using SolrNet. It’s best to somehow add this request bit manually to the query string and is it?

+5
source share
1 answer

Use the class LocalParamsto represent LocalParams in Solr :

solr.Query(new LocalParams {
    {"type", "spatial"},
    {"lat", "-51.5224"},
    {"long", "-2.6257"},
    {"radius", "10000"},
    {"unit", "km"},
    {"calc", "arc"},
    {"threadCount", "2"},
} + Query.Field("text").Is("London"));

It is available as SolrNet 0.3.0b1.

+5
source

All Articles