• 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

    Indexing Specific Field Collection Fields in Apache Solr for Drupal 7

    I’m not sure how much of this is possible without Display Suite, but here’s the setup I’ve used to index specific fields within a field collection as part of the parent entity. I use the “Search index” view mode to specify which fields I want to index on each content type. Here’s what that looks like:


    As you can see, the “Versions” field and the “Associated people / organizations” field are field collections. In this example I only wanted to index a couple of fields from the “Versions” field collection as part of the search index for each “Book” node.

  • Development

    Quickly Implement a Block as a Paragraph in Drupal 7

    Disclaimer: As with most tasks in Drupal, there are several ways to do this. My goal here was to see how quickly it could be done without writing code and without introducing unnecessary complexity.

    Goal — quickly implement a newsletter listing (using Views) that can be dropped into any paragraph field and can have a unique title per use.

    The output would be a simple block from Views. We already use Display Suite, so naturally we use a DS-centric approach.

  • Development

    Bulk Add URL Redirects in Drupal 7

    Here’s a quick example showing how to add URL redirects (for the redirect module) in bulk.

    Instead of a separate page for each list of “fellows”, we built a single view with exposed filters to choose a semester.

    The original paths looked like “/fall-2000-fellows” and the new path looks like “/fellows/list?semester=5493”.


  • 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:

  • Development

    Rendering an Image in Apache SOLR Search results (Drupal 7)


    There are a few ways to get extra information into the output of your Apache Solr Search results. The most efficient ways involve getting the information into the solr index and pulling it directly from the solr index. We do not want to introduce extra node_load()  calls to render our search results. We do not want to have to use Views either.

    So, using just apachesolr and some functions, I’m going to show how to get an image field into the search index and pull it back out in our result output. I know I’m not handling alt and title attributes in this example. I’ll let you figure that one out.

    This is a step-by-step breakdown of my experience getting this to work. In this example I’m attempting to render an image field called field_forum_image for the forum (content type) nodes in my search results. You can use the same procedure for adding other fields, but please make sure you understand the solr prefixes (e.g., ss, ts, tm, etc.) before doing so. You can find these in the schema.xml file with in the apachesolr module.

  • Development

    Importing Paragraph Content with Feeds in Drupal 7

    As I write this, there isn’t an established way to import data into Paragraphs using Feeds.

    This solution only caters to my particular fields, but it should serve as an example of one way to import HTML content into a basic “textarea” paragraph.


    My goal was to import HTML content into a Basic page content type as a basic textarea paragraph item. The original data is from a Drupal 7 typical “body” field, and I want to import the data into a paragraphs-based body field.

  • Development

    Auto-create URL Redirects in Feeds

    I’m working on a website redesign. The original site used awful URL aliases where nearly everything got a URL like /content/title-of-page-would-end-up-looking-like-this. There are no “sections” to speak of in the URL structure, and there are several thousand nodes! I’m migrating most of the content from the “old” site to the new one using Feeds. Rather than manually mess with rewrite rules, I figured I should just create a redirect at the time of migration. We typically handle redirects/rewrites using the redirect module. So, how do you do this?

  • Development

    Adding Metatag Keywords to Search API Index

    For a great explanation of the implementation below, please visit http://enzolutions.com/articles/2015/06/02/how-to-add-customs-fields-to-solr-index-using-entity-api-amp-search-api/

    The following demonstrates how to add metatag keywords (from the Metatag module) to your Search API fields list, so that you can index them and make them searchable.