7

I need to create some custom facets/custom filters for my search. I have Facet API installed; has anyone any experience with this? Ideally, I would use Apache Solr Facet Builder, but this only seems supported in D6.

5

The Apache Solr Search Integration module gives you very good Solr integration and it is actively developed and updated. With this installed you can then go to /admin/settings/apachesolr/enabled-filters and enable a facet block for numerous fields from your content types.

Various CCK fields are automatically sent to Solr however not all are. See here for some extra guidance and check out the comments as they have some useful bits of info on enabling facets. The article is written by the main author of the module itself so he knows what is going on :)

Also http://drupal.org/node/903398 will help you for searching cck fields, note you can only search on text fields and NOT stings. String fields are useful for facets, text fields are for searching.

  • Another note for clarification: to add facets in Drupal 7 with Apache Solr Search Integration, you still also need the Facet API module installed. Just to be clear :-) – geerlingguy Jun 3 '11 at 2:57
4

Facet API allows for custom display widgets by implementing a plugin. The plugin has full access to the render array, so you ultimately have complete control over the the look and feel of the facets.

Plugins are added to the system by implementing hook_facetapi_widgets(), which point to a class that has an execute() method. See the the plugins/facetapi/widget_links.inc file in the Facet API module for an example of a working plugin. Other examples of cool things you can do with Facet API widgets are chart facets and tagcloud facets.

View the Render Arrays in Drupal 7 article at http://drupal.org/node/930760 for how to work with the render arrays in the plugin's execute() method.

Some example code is below:

/**
 * Implements hook_facetapi_widgets().
 */
function mymodule_facetapi_widgets() {
  return array(
    'mymodule_mywidget' => array(
      'handler' => array(
        'label' => t('My Custom Widget'),
        'class' => 'MymoduleMywidget',
      ),
    ),
  );
}

Add the class to a separate file, and set it to be included automatically as described here: http://drupal.org/node/542202

/**
 * My custom widget.
 */
class MymoduleMywidget extends FacetapiWidget {

  /**
   * Renders the widget.
   */
  public function execute() {
    $element = &$this->build[$this->facet['field alias']];

    // $element is the render array that will render the facet.
  }
}
1

If you are still having issues, you can check out the IndexTank module.

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.