There was a small issue with the last patch i submitted. Here is an update.

I'm way to lazy today to make a patch so here is the function replaced :)

FYI. I just started http://drupal.org/project/openlayers_solr which integrates openlayers with apachesolr local solr and uses geofield.


 /**
 * Implements hook_field_instance_settings_form().
 */
function geofield_field_instance_settings_form($field, $instance) {
  $form = array();
  // Add in local solr settings
  if (module_exists('apachesolr')) {
    $setting = isset($instance['settings']['localsolr']) ? $instance['settings']['localsolr'] : array();
    $form['localsolr'] = array(
      '#type' => 'fieldset',
      '#title' => t('Local Solr Settings'),
      '#tree' => TRUE,
    );

    $form['localsolr']['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t('Index field in Local Solr'),
      '#default_value' => empty($setting['enabled']) ? FALSE : $setting['enabled'],
    );

    $form['localsolr']['lat_field'] = array(
      '#type' => 'textfield',
      '#title' => t('Name of the Local Solr Latitude Field'),
      '#default_value' => empty($setting['lat_field']) ? 'lat' : $setting['lat_field'],
    );

    $form['localsolr']['lng_field'] = array(
      '#type' => 'textfield',
      '#title' => t('Name of the Local Solr Lonitude Field'),
      '#default_value' => empty($setting['lng_field']) ? 'lng' : $setting['lng_field'],
    );
  }

  return $form;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

indytechcook’s picture

Status: Active » Needs review
wesnick’s picture

I was actually working on this too, and was hoping to make use of the LatLon field type in solr. Attached my patch, which renames localsolr, solrspatial. I think there are a few different modalities of spatial search in solr, one using the localsolr plugin, and others now using native spatial search. I am not sure about this.

I also cleaned up the geofield_apachesolr_index function to make it apply to fields attached to any entity, as apachesolr module has a forthcoming contrib module call indexer that will index any type of entity known to drupal.

Brandonian’s picture

Status: Needs review » Fixed

Thanks for the patch, wesnick (and initial starter code, indytechcook). Patch has been applied.

wesnick’s picture

There are two problems with this patch that I have fixed.

-Missing updates to hook_field_info()
- not sure if solr_field_mappings would have worked as it was because the bundle property is not universally the type property on entites. added an entity_extract_ids at the beginning of the indexing callback.

Attached patch that will add the widget settings to hook_field_info. Once applying the new settings you will have to go back to widget configuration page and resave to update settings. For new field instances this is not a problem.

wesnick’s picture

OK, sorry about this, the change to the indexing callback is not going to work. The entityType method is not universal to all entities. Not sure if there is a way to reliably determine what an entity is. At any rate, scratch patch from #4, attached revised fix.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

wesnick’s picture

Status: Closed (fixed) » Needs review

I should have marked this as needs review earlier. The current apachesolr callbacks as they are on dev will not work as intended.

Brandonian’s picture

Status: Needs review » Fixed

Thanks for the updated patch, wesnick. I tweaked it a bit to handle entity types that aren't nodes, but otherwise, committed. I don't have a ton of experience with Solr, but I managed to get a server instance running and connected without causing any major explosions. I think it's working, but I'd like to have other eyes on this with more experience.

wesnick’s picture

@Brandonian, I hate to be the guy who pooh-pooh's this commit, but after working with apachesolr extensively for a big project, and having to index non-core entities, I can reliably say that apachesolr module as it is written is not ever going to work well with non-core entities. As it is now, there is not even a suitable dev version that indexes non-core entities. See #966796: Separate indexer for multiple entity types. This issue has been alive for a year on Wednesday and still there is not even a dev branch available for use without applying 50 patches. So the nuts and bolts of it is, IMHO, the original apachesolr field mappings hook in geofield was fine, it worked for nodes, and perhaps other core entities, like taxonomy, because they reliably had ->type property. Entity API entities reliably have ->entityType(), but as you correctly noted in your code, referencing issue #1042822: Developers need an $entity->entity_type property, there is no way to reliable way to get entity type from an entity. Adding this code

function geofield_entity_load($entities, $type) {
  foreach ($entities as $entity) {
    $entity->entity_type = $type;
  }
}

will result in a big performance hit for an entire site, regardless of whether you have apachesolr enabled or not, just so that on the off chance you are indexing non-core entities with apachesolr module, and the entities happen to have a geofield, and you happen to be using SOLR 3.4 (requiring more patches to apachesolr module), because you might want to do some geolocative searching. I think we should revert to the old node-specific field mappings hook, and leave this for the future. In my project, I have used the field property info to manually index these fields on the entities that I want.

Brandonian’s picture

wesnick, I'll defer to your expertise with solr, since I just know enough about it to be dangerous. Just committed a revert back to #5.

wesnick’s picture

@Brandonian, cool thanks! I feel that the future of apachesolr/geofield/custom entities searching lies with the awesome search_api module. I think the approach of using the Entity API module is the correct way to deal with indexing non-core entities. Currently, I am working on merging search_api_location with mollux's work in his sandbox http://drupal.org/sandbox/mollux/1269950, as referenced in #1328490: Support official Solr 3 spatial search APIs. My goal is to create a patch for this module that will remove the dependency on location module so you can use either geofield, or location module, or another lat/lng field storage capable of indexing and searching with solr.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.