September, 2009

Views 3 + Apache Solr + Acquia Drupal = The Future of Search

For the last six months, Scott Reynolds has been keeping a big juicy secret. As the maintainer of the Apache Solr Views module, he knows just how cool the future of Drupal Search is going to be. His module, based on an idea and code from Thomas Seidl, lets you make custom searches against the Solr index the same way you currently make views against the MySQL database. Want to build a search that just includes videos and MP3s, and renders the results as a playlist? Or how about a search that is limited to the current user's images, displayed in a slideshow? How about a block that shows the latest results that contain the phrase "badgers are the new pony"? Well, even if you didn't want a block like that, with Views 3 and Apache Solr Views, you can have it.

Thomas Siedl's brilliant idea was that Views should be able to build "queries" against any data source, not just databases. Earl Miles agreed, and inagurated the Views 3 branch by commiting the patch by Thomas (with great help from Jeff Miccolis and others). With Views 3 I predict you'll be able to build Views using data from Flickr, or from RDF databases using SPARQL, or from the local file system, or from any other data source that has an API.

To test it all out I used the Acquia Drupal Stack to create a new site (I just love the stack's multisite functionality!). I then signed up for a trial Acquia Network subscription because I wanted to get my hands on 30 days of free Acquia Search (it's easier than setting up Solr myself). I then downloaded Views 3 and Apache Solr (DRUPAL-6--2, just for fun. DRUPAL-6--1 works, too). I had to get the Apache Solr Views module from CVS (Scott, make a devel release!). I put these in sites/all/modules so that they'd override the versions in the Acquia Drupal Stack.

The CVS command for getting Apache Solr Views

$ cvs -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib \
co -d apachesolr_views contributions/modules/apachesolr_views

I installed Apache Solr manually which means I also needed to get the SolrPhpClient library. Since I have Drush, and since Apache Solr DRUPAL-6--2 has Drush integration, I did it like this:

$ drush solr phpclient

I <3 Drush!

I then used FeedAPI to grab all sorts of content from Planet Drupal. I could have just as well used Drush and the Devel module to generate some content, but lorem ipsum gets mighty boring. Finally I used Drush to run cron and even did a search (from the command line!) to check that the content was in the index.

$ drush cron
$ # wait a few minutes for the search index to commit the changes...
$ drush solr search drupal
node/175 by admin (user/1)
title: Agile and Scrum Videos
 This is likely to become a pretty big collection of videos about Scrum and
other other Agile based managements processes. (Drupal 5, Drupal 6, Drupal 7,
Drupal Planet, Drupal Video) ...

node/1 by admin (user/1)
title: Welcome to your new Acquia Drupal website!
 If you are new to Drupal, follow these steps to set up your web site in
minutes: Step 1 ... , forums, polls, tags, comments, ratings, and more. Acquia
Drupal comes with many modules to power social publishing capabilities on your
site. Hundreds of additional Drupal 6.x compatible modules ...    

The good stuff

Now for the good stuff. When you make a new view in Views 3 you get asked what data source to use. Here you can see that I use the Apache Solr search index as a data source.

Views 3 asks for data source

Then I added some fields. These are not the same fields that are available to node based views. They are specific to the underlying data source.

Apache Solr fields in Views 3

I also added a sort so that the results would be displayed according to the search score (keyword relevance).

Adding a sort on score

In order to make this view seem like a "search" screen, it needs a search box, right? You get that by adding a search filter and exposing it. I could add more filters, too, like a filter to limit it to just one content type.

Exposing the search filter

This shouldn't just be a copy of the normal search screen. The results should look different. To that end I told Views to render the results in a table.

Tell views to theme the results as a table

Since we want this to be a page view it needs a path, and I went ahead and stuck it in the menu as well.

Finally, I want to be able to use Apache Solr's facet blocks along with the view. This is a three-step process.

  1. First I have to enable the facet filters (I enabled the block for Tags - a taxonomy vocabulary I have) at q=admin/settings/apachesolr/enabled-filters
  2. Then I have to actually place the blocks at q=admin/build/block
  3. Finall, and this is important, I have to pass in an argument to the view to filter by the same "things" that I'm filtering for with the facets. In my example I have the taxonomy facet block enabled, and therefore need to pass in an argument for taxonomy term.

Add an argument for every facet filter you use

How does it taste?

It tastes great! Feast your eyes on this marvelous search screen.

Search results with Views 3 and Apache Solr

The keyword search and the facet block interact seamlessly.

Search term modules and facet filter Drupal 6

An interesting point to note is that there are no database queries used in retrieving the data or displaying it. No complex views query with lots of joins, and no node_load() calls for displaying the results. This method of querying Solr is just as efficient as using the normal Apache Solr search module.

To my mind, Views 3 and Apache Solr Views are the future of Solr search for Drupal. Even though they are both in heavy development, you can try them out and enjoy the great control you have over your search experience. There are many more handlers that need writing, too, so jump into the Apache Solr Views issue queue and help out. Since it all works with Acquia Drupal and Acquia Search, you can easily get up and running using an Acquia subscription. Enjoy!

Commit 269444 by robertDouglass

Commit #269444 by robertDouglass at 08:38
Apache Solr Search Integration: /modules/apachesolr/apachesolr.index.inc 1.1.2.6.4.3 @ DRUPAL-5--2

Commit 269440 by robertDouglass

Commit #269440 by robertDouglass at 08:36
Apache Solr Search Integration: /modules/apachesolr/apachesolr.index.inc 1.1.2.9 @ DRUPAL-6--1

Commit 269436 by robertDouglass

Commit #269436 by robertDouglass at 08:15
Apache Solr Search Integration: /modules/apachesolr/apachesolr.index.inc 1.1.2.6.2.7 @ DRUPAL-6--2

Hänsel and Gretel - Evening prayer and dream sequence

Hänsel and Gretel are hungry and lost. Their mother sent them into the woods in anger after they accidentally spilled the milk - the only food their family had. They picked berries, but Hänsel couldn't help himself and ate them all (he's only a boy!) Darkness has fallen and they've just been visited by the sandman who has made them very tired. Before they fall asleep they say an evening prayer, asking for protection during the night.

When at night I go to sleep
Fourteen angels watch do keep,
Two my head are guarding,
Two my feet are guiding,
Two are on my right hand,
Two are on my left hand,
Two who warmly cover,
Two who o'er me hover,
Two to whom is given
To guide my steps to Heaven.

In the opera, by Engelbert Humperdinck, there then follows an extended orchestral pantomime which is one of the outstanding moments in all classical music. Each opera production does something different with it. The first production I saw revealed a ladder ascending to heaven lined with 14 angels. The Royal Opera House production (clips below) shows the children dreaming. The guardians - half angel half forest creatures - give way to a scene in a home, where a loving father and mother have beautiful presents for Hänsel and Gretel. The treasure inside? Watch for yourselves to see. But listen, too. Listen to what that presents mean. Listen, even as your eyes see, because it is the music which embodies the hearts and souls of the children.

This opera never fails to rip my heart to shreds. The innocence of the children, the terror of being lost in the woods, feeling forsaken by their parents, and the overwhelming pain of hunger all come through in the music. They are so exposed, so alone, and the biggest danger (the Witch!) still lies in front of them. But the music, over all of the darkness and worry, speaks a language of pure beauty and hope. It proclaims with every note the love and divine goodness of our existence.

Embedding web UI components in Eclipse using e4

The demand for software that can be accessed through a web UI is increasing. We already expect software for occasional use (e.g. online shopping, banking, filling out forms, ...) to be accessible from a browser, without having to install anything locally. Over the last few years, more and more producticity applications (email, documents, spreadsheets, etc.) have become available through browsers as well. It is only a question of time until software development tools (at least for a certain class of uses) will have to have a web UI as well. In fact, a few browser-based IDEs already exist, such as Mozilla's Bespin project, and a very recent example: embed, a special-purpose IDE for embedded development.

XDebug, Komodo, and the Acquia Drupal Stack Installer

The Acquia Drupal Stack installer for Mac OS X 10.6 (Snow Leopard) has been released, and it’s pretty cool (works on 10.5 Leopard, too, of course). I’m now using it as my primary development environment, replacing MAMP. In this article I show how you can configure the stack installer to use XDebug for step through debugging. I do so using Komodo IDE, but the steps I follow will help you with Eclipse or any other IDE that supports XDebug. I also install a Firefox plugin called XDebug Helper that makes the whole debugging experience smoothe and sweet.

Plans for DrupalCon Europe, 2010, 2011, have been ratified

Today was a big milestone for the Drupal Association and for the future of European DrupalCons. Over 70 people met in IRC for over two hours to discuss and ratify two documents which lay out the process by which we will select DrupalCon locations going forward, and how the production teams to run DrupalCon will be managed. These are the two documents:

If you belong to a local group somewhere in Europe and you want to see DrupalCon happen in your city, region, or country, read both of these documents carefully. The time for nominating locations is now open, you can read the exact details of how it is done via the links provided above. Nominations must be submitted before October 1. That means there are only six full days to work on proposals. Nominations are being taken for both 2010 and 2011. The nominations will be evaluated, as per the plans in the documents, by October 15. They then get submitted to the Drupal Association Board of Directors, who have to meet and ratify the suggestions.

The important point in all of this is the level of openness and transparancy that is being brought to the system. The Drupal Association is working hard to involve the community in decisions, and to have well defined proceses for making important decisions, like where DrupalCon is held. Today we had a great discourse, thoroughly discussed all of the points that were important to people, and came to nearly unanimous agreements about how things will be done. That is what makes Drupal a nice community to live in.

API compatibility matters

A few weeks ago, Palm has released an SDK called "Mojo" for their WebOS. They also offer Eclipse plug-ins that have been developed for and tested with Eclipse 3.4.2. I just read a short review of this Eclipse-based tooling and was happy to see the following:

The WebOS plug-in is supposed to officially work with Version 3.4.2 of Eclipse (code-named Ganymede). However, I was able to successfully run it on Version 3.5 of Eclipse (code-named Galileo) without any problems.

10 Reasons Smoking is the Dumbest Thing You Do

There are lots of reasons not to smoke. A few of them (like it KILLS you) get emphasized quite a bit. Here are 10 other reasons that sometimes get overlooked.

  1. You cannot sneak up on people from behind because they can smell you coming.
  2. You look like you’re sucking on a really tiny penis. A lot has been made about phallic symbols in advertising, and you are advertising that you like having tiny penises in your mouth.
  3. You have lost your ability to smell things correctly. Examples of things you cannot smell properly: food, flowers, yourself, a smoker sneaking up from behind.
  4. You cause illnesses in children. It’s enough that the smoke is in your clothing, it can make children go deaf.
  5. They tortured dogs and other animals to learn how to make you into an addict.
  6. You’re choking your genitals. Have fun not being able to get an erection later in life.
  7. People at the dinner table talk nasty about you when you go outside to take your smoke break. No, they won’t admit this, but it’s true.
  8. You despise yourself for not being able to quit. The insecurity that this breeds undermines you as a person and reinforces your self image as being weak and unable to control yourself or bring about change in your life.
  9. Smoking is a “gateway drug” to every other habit you are unable or unwilling to control.
  10. Non smokers hate you. Yes, hate you. They might not hate you all the time, but when you smoke, non smokers are definitely thinking “Die and burn in hell, asshole”.

Note: I blame politicians and tobacco corporations for the smoking problem. While it is true that individual smokers are obviously not strong enough to not smoke, I feel the meta problem needs to be legislated away, and that no sum of collective willpower will have any meaningful effect in the absence of legislation.

Commit 266616 by robertDouglass

Commit #266616 by robertDouglass at 12:18
Apache Solr Biblio: /modules/apachesolr_biblio/apachesolr_biblio.admin.inc 1.1Apache Solr Biblio: /modules/apachesolr_biblio/apachesolr_biblio.info 1.1

Commit 266614 by robertDouglass

Commit #266614 by robertDouglass at 12:17
Apache Solr Biblio: /modules/apachesolr_biblio/directory NONE
Directory /cvs/drupal-contrib/contributions/modules/apachesolr_biblio added to the repository

Commit 266590 by robertDouglass

Commit #266590 by robertDouglass at 10:27
Apache Solr Search Integration: /modules/apachesolr/apachesolr.index.inc 1.1.2.6.4.2 @ DRUPAL-5--2

Commit 266588 by robertDouglass

Commit #266588 by robertDouglass at 10:24
Apache Solr Search Integration: /modules/apachesolr/apachesolr.index.inc 1.1.2.8 @ DRUPAL-6--1

Commit 266586 by robertDouglass

Commit #266586 by robertDouglass at 10:13
Apache Solr Search Integration: /modules/apachesolr/apachesolr.index.inc 1.1.2.7 @ DRUPAL-6--1
#584902 by cpliakas initialize array to prevent warning.

Commit 266584 by robertDouglass

Commit #266584 by robertDouglass at 10:13
Apache Solr Search Integration: /modules/apachesolr/apachesolr.index.inc 1.1.2.6.2.6 @ DRUPAL-6--2
#584902 by cpliakas initialize array to prevent warning.

Commit 266582 by robertDouglass

Commit #266582 by robertDouglass at 10:04
Apache Solr Search Integration: /modules/apachesolr/apachesolr_search.module 1.1.2.6.2.111.2.24 @ DRUPAL-6--2

Commit 266580 by robertDouglass

Commit #266580 by robertDouglass at 10:00
Apache Solr Search Integration: /modules/apachesolr/apachesolr_search.module 1.1.2.6.2.112 @ DRUPAL-6--1

DrupalCon Europe: Help plan where and how

Help us decide how DrupalCons in Europe are planned and produced. The draft organizational document is open for feedback and discussion. We’re having an IRC meeting for live discussion in #drupalcon on either Wednesday Sept. 23 or Thursday Sept. 24. If you want to attend please note your availability so that we can schedule the best time for the most people.

Commit 264238 by robertDouglass

Commit #264238 by robertDouglass at 21:32
Apache Solr Search Integration: /modules/apachesolr/apachesolr.module 1.1.2.12.2.155.2.28 @ DRUPAL-6--2

Commit 264230 by robertDouglass

Commit #264230 by robertDouglass at 21:25
Apache Solr Search Integration: /modules/apachesolr/contrib/apachesolr_commentsearch/directory NONE
Directory /cvs/drupal-contrib/contributions/modules/apachesolr/contrib/apachesolr_commentsearch added to the repository
--> Using per-directory sticky tag `DRUPAL-6--2'

Commit 264132 by robertDouglass

Commit #264132 by robertDouglass at 17:14
Apache Solr Search Integration: /modules/apachesolr/apachesolr.admin.inc 1.1.2.28.2.10 @ DRUPAL-6--2

Commit 264108 by robertDouglass

Commit #264108 by robertDouglass at 15:54
Apache Solr Search Integration: /modules/apachesolr/apachesolr.index.inc 1.1.2.6.2.5 @ DRUPAL-6--2Apache Solr Search Integration: /modules/apachesolr/CHANGELOG.txt 1.1.2.99.2.35 @ DRUPAL-6--2

Commit 264096 by robertDouglass

Commit #264096 by robertDouglass at 15:19
Apache Solr Search Integration: /modules/apachesolr/apachesolr.module 1.1.2.12.2.155.2.26 @ DRUPAL-6--2

Commit 264062 by robertDouglass

Commit #264062 by robertDouglass at 14:25
Apache Solr Search Integration: /modules/apachesolr/apachesolr.index.inc 1.1.2.6.2.4 @ DRUPAL-6--2
Followup for the code comments.