I mentioned this to you over the Search Sprint and am only just now getting back to apachesolr. Basically, I'd like to set cck field properties on a per-field basis via your mapping hook. This might look like:

<?php
function apachesolr_cite_apachesolr_cck_field_mappings() {
  $mapping['field_creator'] = array(
    'index_type' => 'string',
    'facet' => TRUE,
    );
  $mapping['field_subject'] = array(
    'index_type' => 'string',
    'facet' => TRUE,
    'callback' => 'explode_cck_field',
    'multiple' => TRUE,
    );    
  return $mapping;
}


function explode_cck_field($node, $key) {
  $to_explode = array_pop($node->$key);
  $field_parts = explode(" ", $to_explode['view']);
  foreach ($field_parts as $field) {
    $fields[] = array('view' => $field);
  }
  return $fields;
}
?>

I've attached a patch that slightly changes the callback to accommodate this finer level of granularity (see above). A few concrete reasons for treating each field individually: (1) automatically indexing and faceting on every field of a given type will be incredibly expensive for Solr, particularly if a given field is very heterogeneous (2) I'd like to be able to assign callbacks on a per-field basis and (3) there may be other things we'd like to tweak for performance or other reasons (ex stored vs indexed only, copy specific fields to text, etc).

Anyway, thanks for supporting this module - we're pretty excited by what you've done already.

Comments

cfennell’s picture

StatusFileSize
new3.37 KB

whoops, looks like my patch didn't attach...here it is...

cfennell’s picture

StatusFileSize
new6.6 KB

A couple of additions:

I've added a callback to override search parameters that were previously hard-coded. If no search params hook is called the search will use the module defaults you provided.

The CCK mapping also now includes an additional dimension (facet_display) that allows modules to provide custom display settings on a per-facet basis to override the default settings.

With field-level CCK mappings, per-facet display settings and search parameter overrides, I'm just about to Solr nirvana.

The only other modification that I'm contemplating right now is to decouple the Solr block item links from the core search module implementation.

I very much appreciate that you've tied ApacheSolr to core search and allow for a default solr search UI there. But I'd also like to build up multiple search UIs on a per URL basis (ex URLS that don't include module implementation details like "apachesolr_search")...that are not tied directly to core search. In order to do that, I'd need links w/in ApacheSolr-provided blocks to be configurable as well.

But, with the current additions, the callbacks look like:

<?php
/*
* Implementation of hook_cck_field_mappings()
* See apacesolr module
*/
function apachesolr_cite_apachesolr_cck_field_mappings() {
  $mapping = array();
  $mapping['field_creator'] = array(
    'index_type' => 'text',
    'facet' => TRUE,    
    );
  $mapping['field_subject'] = array(
    'index_type' => 'text',
    'facet' => TRUE,
    'callback' => 'explode_cck_field',
    'multiple' => TRUE,
    'facet_display' => array(
      'facet.limit' => 2,
      'facet.mincount' => 1,
      'facet.sort' => 'false',
      ),
    );
  }
      
  return $mapping;
}

function apachesolr_cite_apachesolr_search_params($params) {
  $params['rows'] = 10;
  return $params;
}
?>

Thanks.

robertdouglass’s picture

I've looked at this and have to think about it some more. Can you do me the favor of testing it with the new alpha 3 code and make sure everything applies and works as you expect? Thanks.

robertdouglass’s picture

Priority: Normal » Critical

Needs to be evaluated for 1.0 release.

cfennell’s picture

StatusFileSize
new2.31 KB

Hi Robert,

Thanks for considering this patch. Sorry for the delay in my response, I just now saw your note. I downloaded and tested the patch against alpha three and the fields were indexed as expected.

cfennell’s picture

I should have specified that I only tested my patch against 5.x-1.0-alpha3. I'll test 6.x-1.0-alpha3 in the next day or so.

robertdouglass’s picture

@libsys, please test against the .dev versions. We need to get an alpha4 out the door, but until we do, .devs are the best we have to offer.

robertdouglass’s picture

Version: 5.x-1.0-beta2 » 5.x-1.x-dev
cfennell’s picture

Ok, no problem - I'll take a look at both D5 & D6 tomorrow.

cfennell’s picture

StatusFileSize
new4.95 KB

The indexing hook failed on DRUPAL-5/dev version - $key was not being properly set in ApacheSolrUpdate. The attached mapping patch now includes a fix for the related $key variable issue. This patch removes the hard-coding of $document variables:


  $document->nid = $node->nid;
  $document->uid = $node->uid;
  $document->title = $node->title;
  $document->body  = $node->body;
  $document->type  = $node->type;
  $document->changed = $node->changed;
  $document->comment_count = $node->comment_count;
  $document->name = $node->name;
  $document->language = $node->language;

in favor of the dynamic approach taken in alpha3:


$fields = array('title', 'body', 'type', 'uid', 'changed', 'nid', 'comment_count', 'name');
foreach ((array)$node as $key => $value) {
  if (in_array($key, $fields)) {
    $document->$key = $value;
  }
...

robertdouglass’s picture

Just so you know I've been thinking about this: http://acquia.com/blog/understanding-apachesolr-cck-api

pokadan’s picture

Looking forward to see a patch working for D6 or perhaps even have it in the next Apache Solr Search Integration release.

pwolanin’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
StatusFileSize
new2.27 KB

here's what I'm thinking for the 6.x module, perhaps.

pwolanin’s picture

So, seems like do be maximally granular we need 2 subsets of mappings - per field and per widget.

We check the individual fields first, and then when we are checking a certain widget, we skip it if isset($fields[$row->field_name])

pwolanin’s picture

StatusFileSize
new3.76 KB
robertdouglass’s picture

see parallel effort: http://drupal.org/node/444320

pwolanin’s picture

StatusFileSize
new5.21 KB
pwolanin’s picture

Status: Needs review » Fixed

discussed this with Robert - should hopefully be general enough for pretty much any case. If there's a problem, open a new issue.

committing to 6.x

pwolanin’s picture

Status: Fixed » Closed (fixed)