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

  • Which filters have you enabled on this index? – arrubiu Oct 29 '14 at 18:14
  • Tokenizer and Stopwords – Force_IAS Oct 30 '14 at 15:24
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.

| improve this answer | |
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.

| improve this answer | |
  • I have set the fields to String and they are still returned as all lowercase. – usernameabc Jun 21 '19 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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