This is an API module right ? So I think ıt needs to provide a good and clean documentation about how to use this module API for developers.

I want to see how I can create new facets for my custom query pages created with apache solr module query API. I want to see how can I create my own facets with (I think) hook_facetapi_facet_info from scratch using facet API.

Is there an example about this somewhere on the internet ? Because I couldn't find anything.

Comments

yusufsarac’s picture

Title: Where is the documentation for creating custom facets for custom query pages » Where is the documentation for creating custom facets for custom query pages ?
cpliakas’s picture

It would be helpful to understand what could be more clear in facetapi.api.php, as that is intended to show how to implement the various hooks.

Since you are working through this process and are having a hard time working with the existing documentation, I think you are in a perfect position to help identify the pain points and contribute back what you learned.

yusufsarac’s picture

I'd love to do that. But I'm stuck now because I don't know how to start creating a custom facet block for custom query page.

I mean Facet API uses the default query created by apache ssi or search api modules. What I want is change that to my custom solr query somehow, and make facets for that custom page.

May be you can help me with that for a start and I can go from there and write some tutorials about the api.

marcoka’s picture

jcfiala’s picture

Yeah, I agree. I'm trying to create a new facet. I have no idea how a facet, such as the bundle one that comes out of the box with facetapi in the facet module, actually modifies the search query to restrict it to only show the selected bundle(s). I'm trying to figure this out, and there's no documentation.

Basically, if I have a custom entity X, and I have a property on this custom entity, how do I create a facet for that property?

alecsmrekar’s picture

@jcfiala Have you found any documentation on this? I'm also struggling.

botris’s picture

Creating a facet for a property on custom entity X (as requested in #5), you need to:

  1. Make sure the item is in the index (this differs per search provider)
  2. Add the custom entity to the searcher definitions
  3. Define the facets

Adding the custom entity to the searcher definitions is done by hook_facetapi_searcher_info()

function MYMODULE_facetapi_searcher_info_alter(array &$searcher_info) {
  foreach ($searcher_info as $index => $info) {
    $searcher_info[$index]['types'][] = 'MYENTITY';
  }
}

Defining the facets is done by hook_facetapi_facet_info()

function MYMODULE_facetapi_facet_info($searcher_info) {
  $facets = array();

  if (isset($searcher_info['types']['MYENTITY'])) {
    $facets['UNIQUE_PROPERTY'] = array(
      'label' => t('Unique property'),
      'description' => t('Filter by unique property.'),
      'field' => 'UNIQUE_PROPERTY_FIELD',
    );

    // Add facets for all fields attached to the custom entity.
    $facets = array_merge($facets, apachesolr_entity_field_facets('MYENTITY'));
  }

  return $facets;
}

Of course the array_merge is optional if you don't want all fields exposed as facets.