1

I have an issue with Facets on search API (Solr Integration).

  • Facets items are all in lowercase, and thats not how the content type save them, and I've made a query to solr server directly and the index items there have uppercase letters

can someone help me ?

Thx

2
  • Which filters have you enabled on this index?
    – arrubiu
    Oct 29, 2014 at 18:14
  • Tokenizer and Stopwords
    – Force_IAS
    Oct 30, 2014 at 15:24

2 Answers 2

4

You could use hook_facetapi_filters() to define a new filter for your facets.

/**
 * Implements hook_facetapi_filter().
 */
function MODULE_facetapi_filters() {
  return array(
    'uppercase_items' => array(
      'handler' => array(
        'label' => t('Uppercase items'), 
        'class' => 'FacetapiFilterUppercaseItems',
      ),
    ),
  );
}

and then extend the FacetapiFilter class like this:

class FacetapiFilterUppercaseItems extends FacetapiFilter {

  /**
   * Filters facet items.
   */
  public function execute(array $build) {
    // Do your magic.
    foreach ($build as $key => $value) {
      $build[$key]['#markup'] = ucfirst($value['#markup']);
    }
    return $build;
  }

  /**
   * Adds hook documentation.
   */
  function settingsForm(&$form, &$form_state) {
    $form['uppercase_items'] = array(
      '#title' => t('Uppercase filters'),
      '#type' => 'checkbox',
      '#default_value' => TRUE,
    );
  }     
}

I haven't actually tried this out but this is pretty much what Facet API Bonus does, which is also a great example for creating your own filters.

0

If your fields are of type "fulltext" (or a variant of fulltext), the captialization may be getting stripped out by an "ignore case" processor in Solr or in Search API.

You can add the same field again, but a) Drill down to the "Name" field using the (+) sign next to the field as you add it (e.g. Authored by » User » Name), and b) Choose type "String" for the field. Then use that field for your facet, instead of the first one. The facet label should then include capitalization, if the field's value is actually capitalized.

Another advantage is that string fields in facets can display multiple words, which may not be the case if you're using fulltext fields.

1
  • I have set the fields to String and they are still returned as all lowercase. Jun 21, 2019 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.