Does this work with search api location views? I have a location field in my index as a location type and have chosen it as a filter.. Just wondering if anyone has gotten this to work?

Comments

rulley created an issue. See original summary.

jmdeleon’s picture

It's probably not likely to work... It looks like Search API Location Views is designed to work with native Drupal Geofields and Location Fields, whereas Sarnia is designed to work with Solr indexes of non-Drupal-native data.

If you are using Location Fields in your index, you are dealing with an index of Drupal data, and you do not Sarnia at all for this case.

I'm not sure of your use-case, as you've not described it at all, but if you are looking at mapping arbitrary Views data you might have better luck with the Openlayers project.

rulley’s picture

The goal is to be able to have a views exposed filter where a city/state or zip field and a mile radius will be entered and then a spatial search against a solr location field will run.. (just like the search api views location) I have a fieldtype in my external solr index that is a location type with lat,long . I came across a post where users needed add additional field types for views grouping (http://www.mediacurrent.com/blog/solr-integrations-drupal-sarnia-module)... I thought that if I could add my already exisiting solr location field as a Latitude/longitude field type this same way with the field name as location per the search api location and search api location views readme files it may work.. any ideas?

/**
* Implements hook_search_api_index_load().
*/
function mymodule_search_api_index_load($indexes) {
// Sarnia module only sets a type for fulltext fields, so we set it manually.
if (!empty($indexes['sarnia_solr5_resumes']->options['fields']['location'])) {
$indexes['sarnia_solr5_resumes']->options['fields']['location']['type'] = 'location';
}
}

/**
* Implements hook_entity_property_info_alter().
*/
function mymodule_entity_property_info_alter(&$info) {
// Add a definition for our grouping field. Left to its own, Sarnia module
// only adds properties for fulltext fields. This causes errors to be to be
// thrown when we do our grouping implementation.
if (isset($info['sarnia_solr5_resumes']['properties'])) {
$info['sarnia_solr5_resumes']['properties']['location'] = array(
'type' => 'location',
'label' => 'location'
);
}
}

rulley’s picture

found a solution... just add custom module and then form fields for the lat long and distance.. Just tried them hardcoded and it works.

function mymodule_search_api_solr_query_alter(array &$call_args, SearchApiQueryInterface $query) {

  $lat = 33.467531;
  $lng = -117.692029;
  $distance = 20;

  $call_args['params']['fq'][] = "{!geofilt sfield=location pt={$lat},{$lng} d={$distance}}";

}
jmdeleon’s picture

Status: Active » Closed (fixed)