Posted by pwolanin on October 22, 2010 at 4:01pm
5 followers
| Project: | Apache Solr Search Integration |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | pwolanin |
| Status: | closed (fixed) |
Issue Summary
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.
Comments
#1
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.
#2
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.
#3
committed my patch to 6.x-1.x. Here's a starter patch for 6.x-2.x
#4
Here's a
hook_apachesolr_cck_fields_alterimplementation 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
#5
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.
#6
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"
#7
#8
Which patch are you saying is RTBC?
#9
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.
#10
committed to 6.x-2.x
#11
Automatically closed -- issue fixed for 2 weeks with no activity.