• Development

    Pointing All Taxonomy Term Links to ApacheSolr Search Results

    I’ve been working on a project that leverages ApacheSolr for many of the displays on the site. One of the requirements is that every instance of a taxonomy term link on the site needs to point to search results pre-filtered (using FacetAPI) on the term. The other requirement is that if a taxonomy term’s vocabulary doesn’t have an associated search facet, the user should end up on the search page with results as if the user had searched for the term’s name in the search text box.

    1. If you see a “Climate Change” term (tid = 153) link from the “Topics” vocabulary (vid = 8), it should render as  <a href="/search/site?f[0]=im_field_tr_topics%3A153">Climate Change</a> in the DOM.
    2. If you see a “Blog” term (tid = 123) link from the “Keywords” vocabulary (vid = 6), it should render as  <a href="/search/site/blog">Blog</a> in the DOM.
  • Development

    Adding a “Filter by year” Facet for a Date Field in Apachesolr for Drupal 7

    A Drupal 7 site I’m working on makes use of the Apache Solr Search module and FacetAPI. Some of the content has a date field named field_s_date. I was tasked with providing a sidebar “Filter by year” facet block to filter the content by the year value of this date field. I’m pretty sure I could have done this a few different ways, but I settled on adding the year value as a separate field to the solr index and adding an associated facet using hook_facetapi_facet_info() .

    First, to add the field, I used hook_apachesolr_index_document_build() in a custom module as follows: