Affinity Bridge was using the Drupal 6 Searchlight module previously. Searchlight had three things going for it:
- You could plug it into the popular Apache Solr search platform.
- you could plug it into the Sphinx search platform.
- It worked with the Views module for displaying search tools and search results.
What it didn’t have was compatibility with Drupal 7. (There’s a broken fork of it on Github, but that’s it.) Katherine heard about Search API and thought it might work. This comment by Robert Douglass largely convinced her:
“I can tell by the usage statistics that you haven’t tried the Search API module yet! Run, don’t walk, to the download page and give it a go. You’ll have to pick yourself up a copy of the Entity module as well, but then you’re all set.”
Search API is all about adaptability, Katherine says.
Setting Up a Search
When setting up a search, there are three categories to think about:
- How will the search perform?
- What will the results look like?
- What extra features will be available on the search page? (ie. facets, “more like this”, spelling suggestions, etc.)
Search API lets you answer these questions no matter the search platform you are using.
On Search API’s main administration page, you accomplish:
- choosing your search server/platform – give it a name and description, and set the path to connect to Solr, or whatever backend you are using.
- setting up an index – again, give it a name; then specify what entity type it will index. “Node” – Drupal’s term for what is typically referred to as a “page” on a web site, is the most common entity specified.
You can perform searches across indexes.
Your next steps will be:
- choosing the fields of your content that you want indexed. Content management systems generally parse out elements of a page, or node, into fields. “Title” and “Body” are typical content fields – and ones you might typically index. Other field examples include date that content is posted or updated, author and comments.
- If you want to search on particular fields, use a string.
- If you cannot find the field you want indexed, check the “related fields” section.
- The Workflow tab allows you to customize how your index works. “Aggregated fields,” for example, let you create a new field based on processors.
Search API, Katherine says, is “beautifully architected” and thus easy to extend with your own custom plugins.
Facets API is a module that works along side Search API. Facets of a search are like categories. They allow users to search by author, organization, topic, (subtopic ad infinitum!), date ranges, etc. Facets API lets you create guided searches for your users, and display them in user friendly ways. You can create dropdown lists, for example, that users click or un-click to narrow and/or widen search results. Facets API works with search modules other than Search API – you can use it with whatever search module you decide to you. You can only facet what is indexed.
Tom Nightingale walked through Affinity Bridge’s search set up for the University of Ottawa. This set up included a calendar system to manage events for faculties, sub organizations within faculties, and their associated staff, students and potential students. Categories, in effect, shifted from faculty and from sub-organization to sub-organization, all having differing needs. Additionally, as a bilingual university, content existed in both french and english.
- After defining servers and indexes, Affinity Bridge thought “great, we can use the Views module, date, slideshow, etc.”; however, Views for Drupal 7 is very modular and made to work with the MySql database while their implentation of the Search API swapped out the Sql backend for Solr. Workarounds were needed.
- Creating lists of events, grouped by organizations, also needed workarounds because the concept of aggregation doesn’t exist in Solr.
- Drupal’s Date module supports repeating dates, and stores this data as a multi-value field; however, Solr has its own native date handling which does not line up with the Sql-based repeating date data storage. Affinity Bridge used the concepts of entities from Drupal 7 to deal with this issue: by creating an entity, they could split the repeating date values into separate entities.
- Internationalization: one of required fields on entity is language. Search API indexes language so you can use Views filters to display the current language. However, if you want to do more complicated language filtering: showing all french entries if they exist, or english entries if no french entry exists, for example, Search API cannot handle it. Again, workarounds needed to be implemented.
Search API Summary
- Anything that’s an entity can automatically be indexed.
- It is possible to index non-entity content by specifying an external source of data and sending it to a Solr index.
- You can set up multiple indexes, and even perform multi-index searches, using the Search API multi-indexes module.
- You can use multiple search servers, including Mongo DB.
- There is a powerful system of plugins available for altering data during the indexing process, and tons of hooks and alter hooks.
- all configurations are exportable to features,
- excellent views integration, and
- faceting, via the Facet API module.
- Setting up Apache Solr: http://zugec.com/73-how-setup-search-api-apache-solr – “it’s dead easy,” says Katherine.
- Affinity Bridge’s profile for setting up Search API and Facet API: https://github.com/affinitybridge/d7search
- Katherine’s blogpost on Search API: http://affinitybridge.com/blog/pluggable-search-components-search-api-and-facetapi