Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Nick_vh’s picture

Status: Active » Closed (works as designed)

This is a facet api question. The answer should be to define a map_callback for the specific facet.
Take a look at facetapi_map_bundle to see how that works

chrisrikli’s picture

Here's how I did it:

function mymodule_facetapi_facet_info_alter(array &$facet_info, array $searcher_info) {
  $facet_info['myfacetname']['map callback'] = $facet_info['myfacetname']['map options']['map callback'] = '_mymodule_facet_create_label';
}

function _mymodule_facet_create_label(array $values, array $options) {
  $map = array();
  
  if ($options['field']['type'] == 'list_boolean') {
    foreach ($values as $value) {
      $map[$value] = $value == 'true' ? t('Yes') : t('No');
    }
  }
  else {
    $map = facetapi_map_bundle($values, $options);
  }

  return $map;
}

It's a little crude and should be refined to catch all boolean fields and map the values assigned in the field's user interface. But it works.

j0rd’s picture

Category: support » bug
Status: Closed (works as designed) » Needs review
FileSize
789 bytes

This is actually a bug in apachesolr, as the code which is written isn't working as the programmer expected it to IMHO. There's a slight oversight which is causing this issue.

When a boolean facet in ApacheSolr get's returned, the values are "true" & "false".

When "allowed_values" for a boolean Drupal field are stored, they are keyed as "0" and "1".

This means when we're trying to get the human readable values, we're comparing mix matched types....and we find nothing, then display the solr value.

I'm pretty sure this is a slight over sight and in fact a bug.

Here's a patch which resolves the issue.

j0rd’s picture

double post sorry.

Nick_vh’s picture

Status: Needs review » Needs work

Looks reasonable.

+++ b/apachesolr.moduleundefined
@@ -2040,6 +2040,13 @@ function apachesolr_fields_list_facet_map_callback($facets, $options) {
+      $allowed_values[$key ? 'true' : 'false'] = $value;

I just don't like this small programming manner. It makes it complex to read. Certainly if it is used inside the id of an array value.

j0rd’s picture

Status: Needs work » Needs review
FileSize
1.17 KB

Removed the ternary operator.

j0rd’s picture

Patch above is wrong. Has a typo. This one is correct.

Status: Needs review » Needs work

The last submitted patch, apachesolr-booleanallowedvalues-1757470-7.patch, failed testing.

j0rd’s picture

Status: Needs work » Needs review
FileSize
1.19 KB

Another typo. One last time.

pwolanin’s picture

FileSize
1.35 KB

fixed if() to a ternary and improved code comment.

pwolanin’s picture

Status: Needs review » Fixed

committed to 7 and 6

Status: Fixed » Closed (fixed)

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