After struggling to integrate my profiles with apache solr, I would like to make this contribution for the next person who tries:

This module is by design lightweight and serves only as an integration module, defering all heavy lifting to the profile2, entity and solr modules. Here is in abstract how the module functions:

The profile2_apachesolr module alters the entity registered by the profile2 module, exposing it to apache solr. When triggered for a re-index by the apachesolr module, it processes all eligible profiles by rendering them in the newly added viewmode "search index". The rendered content is then stored in the search documents body send to the solr server for indexing.

Now the step-by-step guide to implement your profiles:

1. Make sure the apache solr framework knows what profile2(entity) types (bundles) it needs to index.
After enabling the module visit the following administration url: /admin/config/search/apachesolr. There now should be an extra entity group named profile with all its types. Enable the profile types appropriate for your configuration.

2. Flag the wanted profile fields for indexing
Visit the the administration url: /admin/structure/profiles. Here navigate to the "manage display" page for the enabled profile types in step 1. Navigate to the sub tab "search index". By default all profile fields are disabled (hidden). Display all the fields you want apache solr to index about your profiles. Repeat this step for all profile types enabled in step 1.

3. Reindex your profiles

Caveat: Use of profiles in collaboration with the field_permissions module
By design apache solr (by default) indexes the content as the anonymous user. If you don't manually change this, make sure the fields you have included in step 2 at least permit viewing by the anonymous user. Otherwise no content will be indexed.

Caveat: Use of profiles in collaboration with the apachesolr_attachments module
As the file by itself is indexed as a separate entity by the attachments module you don't have to worry about it. Except that when the files show up in the results, they won't have the nice "attached to" line like on the nodes. Below is a snippet of how you can hook into the theme system in a way that addresses this issue. This might require some tinkering differing per situation.

function [yourmodule]_theme() {
  return array(
    'apachesolr_search_snippets__profile2__file' => array(
      'variables' => array('doc' => NULL, 'snippets' => array()),
    ),
  );
}

function theme_apachesolr_search_snippets__profile2__file($vars) {
  $doc = $vars['doc'];
  $snippets = $vars['snippets'];
  $parent_entity_links = array();

  // Retrieve our parent entities. They have been saved as
  // a small serialized entity
  foreach ($doc->zm_parent_entity as $parent_entity_encoded) {
    $parent_entity = (object) drupal_json_decode($parent_entity_encoded);
    
    $user = profile2_get_user($parent_entity->pid);
    
    $parent_entity_uri = 'user/'.$user->uid;
    $parent_label = $user->name;
    $parent_entity_links[] = l($parent_label, $parent_entity_uri, array('options'=>array('absolute'=>true)));
  }

  if (module_exists('file')) {
    $file_type = t('!icon @filemime', array('@filemime' => $doc->ss_filemime, '!icon' => theme('file_icon', array('file' => (object) array('filemime' => $doc->ss_filemime)))));
  }
  else {
    $file_type = t('@filemime', array('@filemime' => $doc->ss_filemime));
  }

  return implode(' ... ', $snippets) . '<span>' . $file_type . ' <em>attached to:</em>' . implode(', ', $parent_entity_links) . '</span>';
}

function profile2_get_user($pid){
  $statement = db_select('profile','p');
  $statement->join('users','u','p.uid=u.uid');
  $statement->fields('u');
  $statement->condition('p.pid',$pid);
  $result = $statement->execute();
  $user = $result->fetchObject();
  return $user;
}

Comments

pwaterz’s picture

Thanks for the post!

pwaterz’s picture

Issue summary: View changes

changed tandem > collaboration

DrCord’s picture

Thank you for documenting the caveat of the permissions, the anonymous user having to be able to access them was the solution to my problem that I had been trying to figure out for hours!