tags:

views:

377

answers:

1

Hi,

I am running Solr on my windows machine using jetty. I have downloaded the Spatial Solr Plugin which I finally managed to get up and running. I am also using Solrnet to query against Solr from my asp.net mvc project.

Now, adding data into my index seems to work fine and the SpatialTierUpdateProcessorFactory does work as well.

The problem is:

How do I add the spatial query to my normal query using the Solrnet library. I have tried adding it using the "ExtraParams" parameter but that didn't work very well.

Here is an example of me trying to combine the spatial query with a data range query. The date range query works fine without the 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 results in the following query against 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 I get back is:

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, the thing is if I use the Solr Web Admin page and execute the following query 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/correct way to call the spatial function using SolrNet. Is the best way to somehow add that bit of the query manually to the query string and is so how?

Any help is much appreciated!

+1  A: 

Use the LocalParams class to 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"));

This is available as of SolrNet 0.3.0b1.

Mauricio Scheffer
Cheers! Exactly what I needed. I got it working by messing around with the query string manually but your solution is the better/cleaner way to go. Thanks a lot!
Flo