I got very frustrated just now with the existing code - we should index all text an integer fields using optionwidgets - for example, an int on/off checkbox could be very handy as a facet of for query-time boosting.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

robertDouglass’s picture

Yes. Can we do these things in the 6.x-2.x branch? It already has a much more flexible API for dealing with CCK.

pwolanin’s picture

Status: Active » Needs review
FileSize
1.75 KB

starter patch.

Note I used sint by default since I assume people might rely on the sort-missing-last functionality. Could be tint instead, however.

pwolanin’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
FileSize
3.39 KB

committed my patch to 6.x-1.x. Here's a starter patch for 6.x-2.x

davidwhthomas’s picture

Here's a hook_apachesolr_cck_fields_alter implementation I used to successfully add facets for integer fields for apachesolr version = "6.x-1.2"
In this case it was for real estate listings to provide 'Bedrooms' and 'Bathrooms' facets.

<?php
/**
* Implementation of hook_apachesolr_cck_fields_alter
*
* @param $mappings
*   The existing array, received by reference, of the cck mappings.
*/
function [MODULENAME]_apachesolr_cck_fields_alter(&$mappings) {
  $mappings['number_integer'] = array(
    'number' => array(
      'callback' => '',
      'index_type' => 'integer',
      'facets' => TRUE,
    ),
    'optionwidgets_select' => array(
      'callback' => '',
      'index_type' => 'integer',
      'facets' => TRUE,
    ),
    'optionwidgets_buttons' => array(
      'callback' => '',
      'index_type' => 'integer',
      'facets' => TRUE,
    ),
    'optionwidgets_onoff' => array(
      'callback' => '',
      'index_type' => 'integer',
      'facets' => TRUE,
    ),
  );
}
?>

You'll also then need to enable the facets at: /admin/settings/apachesolr/enabled-filters

HTH,

DT

davidwhthomas’s picture

And one more update, here's what I needed to do to get integer field facets working with version = "6.x-2.0-beta3"

<?php
/**
* Implementation of hook_apachesolr_cck_fields_alter
*
* @param $mappings
*   The existing array, received by reference, of the cck mappings.
*/
function example_apachesolr_cck_fields_alter(&$mappings) {
  $mappings['number_integer'] = array(
    'number' => array(
      'indexing_callback' => 'example_integer_indexing_callback',
      'display_callback' => 'apachesolr_cck_text_field_callback',
      'index_type' => 'integer',
      'facets' => TRUE,
    ),
    'optionwidgets_select' => array(
      'indexing_callback' => 'example_integer_indexing_callback',
      'display_callback' => 'apachesolr_cck_text_field_callback',
      'index_type' => 'integer',
      'facets' => TRUE,
    ),
    'optionwidgets_buttons' => array(
      'indexing_callback' => 'example_integer_indexing_callback',
      'display_callback' => 'apachesolr_cck_text_field_callback',
      'index_type' => 'integer',
      'facets' => TRUE,
    ),
    'optionwidgets_onoff' => array(
      'indexing_callback' => 'example_integer_indexing_callback',
      'display_callback' => 'apachesolr_cck_text_field_callback',
      'index_type' => 'integer',
      'facets' => TRUE,
    ),
  );
}

function example_integer_indexing_callback($node, $field_name, $cck_info) {
  $fields = array();
  if (isset($node->{$field_name})) {
    $cck_info['index_type'] = 'integer'; // needed?
    $index_key = apachesolr_index_key($cck_info);
    foreach ($node->$field_name as $field) {
      if ($index_value = isset($field['value']) ? (int) $field['value'] : FALSE) {
        $fields[] = array(
          'key' => $index_key,
          'value' => $index_value,
        );
      }
    }
  }
  return $fields;
}
?>

I see the new code has facet info for some integer fields, but not the default 'number' one.
So perhaps the other widget types aren't needed here.

joetsuihk’s picture

Status: Needs review » Needs work

below is invalid, sorry

the patch #3 on 6.x-2.x-beta3 do not add integer with widget "textfield"

It only add widget "select" or "checkbox"

joetsuihk’s picture

Status: Needs work » Reviewed & tested by the community
pwolanin’s picture

Status: Reviewed & tested by the community » Needs review

Which patch are you saying is RTBC?

joetsuihk’s picture

Status: Needs review » Reviewed & tested by the community

patch #3 tested on 6.x-beta3.

I have no idea what #5 is talking about, but i can have filters on integers value that use dropdown/checkbox as widget.

pwolanin’s picture

Status: Reviewed & tested by the community » Fixed

committed to 6.x-2.x

Status: Fixed » Closed (fixed)

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