Search code examples
solrfull-text-searchspatialsolrnet

Using SolrNet for Spatial Search and multiple Columns


I am new to Solr. Using following Solrnet query to run my search.

results = solr.Query(new LocalParams { { "type", "dismax" }, { "qf", "Title Description" } } + new SolrQuery(Keywords) , queryOptions);

The above query works without any issues. I tried spatial search in the same query using following.

results = solr.Query(new LocalParams { { "type", "dismax" },{ "pt", "40.7143528,-74.0059731" },{ "sfield", "coords" },{ "d", "15" }, { "qf", "Title Description" } } + new SolrQuery(Keywords) , queryOptions);

Above query doesn't take spatial search into account, it rather return results from all documents.

The same query does a spatial search if change the "type" to "geofilt".

results = solr.Query(new LocalParams { { "type", "geofilt" },{ "pt", "40.7143528,-74.0059731" },{ "sfield", "coords" },{ "d", "15" }, { "qf", "Title Description" } } + new SolrQuery(Keywords) , queryOptions);

But this time, it doesn't return the relevant results. i.e. if user searched for "Toyota", above query with type=geofilt might return "FORD" within 15 kms.

Can you please guide me to the right direction?


Solution

  • There are two clauses here: the dismax query by keywords, and the geospatial query, but you're trying to cram both into a single clause. Instead, represent them as separate query clauses (separate query objects).

    Pseudocode:

    var spatial = new LocalParams {{"type","geofilt"},...} + new SolrQuery("");
    queryOptions.FilterQueries = new[] {spatial};
    var keyword = new LocalParams { { "type", "dismax" }, { "qf", "Title Description" } } + new SolrQuery(Keywords);
    var results = solr.Query(keyword, queryoptions);