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

    Introduction

    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.

  • Tech Tips

    Use Keyboard Maestro to Hide Instead of Close an Application

    I use SnagIt to capture screenshots. The editor window that appears after you capture takes a few seconds to open if the application isn’t running. I realized that, while the capture tools remain open, the editor goes away when I hit ⌘W to close the window. Instead of using ⌘W to close the editor window, I sometimes remember to use ⌘H to hide the window, which hides the window but leaves the application open. The editor window pops open much quicker if the application is still open.

    Using Keyboard Maestro I’m able to intercept the ⌘W that I do all the time (muscle memory), and turn that into a ⌘H.

  • Tech Tips

    Launch Center Pro actions for Day One

    Here are my Launch Center Pro actions for the Day One app on iOS. I’m not here to teach you how to use Launch Center Pro (a huge topic), so if you need to learn that I suggest a lot of Googling and perhaps a visit to their official documentation and FAQs. Basically LCP will step you through prompts as it builds the output to move into a new Day One journal entry. Day One supports markdown, so you can make entries that look nice, like this:

    2016-02-15_06-15-13

    Use this LCPEncoder to convert the templates you see below into URLs. After you generate the URL, get it into the “url” field of the LCP action.

  • Development

    Recursively Finding and Operating on the Largest n Number of Files of a Particular Type

    If you want to reverse-engineer this, you can work from left to right, adding one command at a time to see what each step does to the output.

    2016-02-03_15-52-47

    This example just lists the files we found, which is pointless given that’s what we already had before introducing the cut command.

    How about a practical example?

    Here’s how you can resize the 25 largest jpg files using mogrify (part of ImageMagick) to reduce the quality to 80:

    What if you wanted to only grab files that are larger than a specific size? One way to do it is with the find command. For example, find all files greater than 8M:

     

  • Development

    Extracting Image “src” Attributes from an HTML String using PHP

    Here are a few ways to build an array of image sources extracted from an HTML string. I’m sure there are other ways, but these seem to be reliable.

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

    Goal

    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.