Attached it is a first pass at adding support fro non-cck field data to (a) the indexing process and (b) facet block generation. My test use case was to index some field data from the biblio module, which stores citation data in its own table structure. The hook implementation looks like this:

/*
* Implementation of hook_apachesolr_custom_field_mappings()
*/
function biblio_apachesolr_custom_field_mappings() {
  $mappings = array();
  $mappings['biblio_secondary_title'] = array(
    'index_type'    => 'string',
    'field_name'    => 'biblio_secondary_title',
    'label'         => t('Biblio Publisher'),
    'is_multiple'   => FALSE,
    'facet'         => TRUE
    );
  $mappings['biblio_contributors'] = array(
    'index_type'    => 'string',
    'field_name'    => 'biblio_contributors',
    'label'         => t('Biblio Contributors'),
    'is_multiple'   => TRUE,
    'callback'      => '_biblio_index_contributors',
    'facet'         => TRUE
    );

  return $mappings;
}

//helper callback - cram all types of authors into one field
function _biblio_index_contributors($node, $fieldname) {
  $contrib = biblio_parse_contributors($node->biblio_contributors);
  foreach ($node->biblio_contributors[1] as $contributor) {
    $contributors[] = sprintf('%s, %s %s', $contributor['lastname'], $contributor['firstname'], $contributor['initials']);
  }
  return $contributors;
}

A couple of things to note:

  1. In apachesolr_search.module, $index_key needed a $delta concatenated to it for CCK/custom fields w/in apachesolr_facet_block(), so I added that
  2. I implemented temporary fix for granular field mappings to test some non-option widget CCK fields (see 271753)
CommentFileSizeAuthor
apachesolr_custom_field_mappings.patch12.97 KBcfennell

Comments

robertdouglass’s picture

pwolanin’s picture

A custom module can already add data to the index (e.g. the og_apachesolr module is basically example code for this).

Why do we need an additional mechanism?

cfennell’s picture

Status: Needs review » Closed (works as designed)

@pwolanin Thanks, I'll have a look at og_apachesolr - so many positive changes have happened since the last time I looked at this stuff, I should have been more diligent in looking at the additional implementations.

The only thing that looks obvious to me is that the current mechanism is a bit more involved on the API side than a simple hook. But the OG implementation does look pretty clean, and I wouldn't argue for the additional hook (redundant code) solely on this basis.

I'll parse through again and see if there is anything otherwise missing, but your OG example looks very complete.

Marking "by design" just to close this until I have a change to test your API.

fak3r’s picture

Status: Closed (works as designed) » Needs review

I'm having this same issue, I need Solr to index Authors and Published dates under Biblio; currently it's only looking at Drupal users for authors, and node date for Published dates. I'll take a look at the og_apachesolr module now, but since I've found many posts looking for a similar solution, I wanted this to be reviewed before I set it back to "by design".

pwolanin’s picture

@fak3r are those CCK fields or custom module fields?

fak3r’s picture

They are custom module fields, created by Biblio. You can see it in action here: https://www.ethicshare.org/publications/author%253Asmith?author=smith&sc...

Notice down the left gutter there is 'Refine by Author' and 'Refine by Year Published', both being pulled from a Biblio field. So I guess I'm wondering if using apachesolr_og module is the way to build these, and how. If it's not, feel free to close this, but I'm desperately looking for a solution. Thanks

pwolanin’s picture

Status: Needs review » Closed (fixed)