I'd like to allow my site users to drill down to the month level only. I found the place where this is set to minute by default, in ApacheSolrFacetapiDate::getDateRange() in plugins/facetapi/query_type_date.inc. So I understand if I don't want to hack apachesolr I need to somehow override this method. Looking through the code, it seems the right way to do this is to implement my own query type plugin. I can implement something like this

/**
 * Implements hook_facetapi_query_types().
 */
function apachesolr_facetapi_query_types() {
  return array(
    'mysearch_date' => array(
      'handler' => array(
        'class' => 'MySearchFacetapiDate',
        'adapter' => 'apachesolr',
      ),
    ),
  );
}

and include my MySearchFacetapiDate class via my .info.

What I don't understand though is how my custom query type 'mysearch_date' is going to be used instead of the default apachesolr_date. I've grepped 'apachesolr_date' (key used in the apachesolr hook implementation) through apachesolr but I failed to see where this is set so that Drupal/FacetApi knows to use my custom query type. Also checked my export facet settings and could not find it.

Comments

cpliakas’s picture

Sorry for missing this!

So this is a bit wonky, but how it works is that the custom query type is tied to an adapter (such as "apachesolr"), and then the query type plugin implements the FacetapiQueryTypeInterface::getType() method to register the machine name of "date", or something else in your custom plugin's case. The adapter then matches the facet's "query types" key to see which query type plugin to execute. If a facet supports multiple query types, then there will be a configuration option to select which one to use in the facet's global settings. In order the facet to select your custom query type, you will have to implement hook_facetapi_facet_info_alter() and add your machine name to the "query types" key for the appropriate facets.

Make sense?
Chris

cpliakas’s picture

Status: Active » Fixed

Marking as fixed after weeks of inactivity.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

minor edit