search

Tweaking Drupal Search

Djun Kim - October 8, 2007 - 10:51pm

I've recently been doing work extending and adapting Drupal's search module, and I thought I'd take the opportunity to show just how easy it is to tweak search module's indexing behaviour.

One of the issues I was asked to address is the default behaviour of search module with respect to hyphenated words. One might reasonably expect that searching for 'intuitive' or 'counter' would find a post containing the hyphenated word 'counter-intuitive'. However, search module will by default not return a match unless you type 'counter-intuitive', or 'counterintuitive'.

Reading through the code for search module, we find that embedded dots, underscores and hyphens are simply stripped out of words, to allow meaningful search behaviour for URLs and acronyms.

Fair enough - we'd like searches for 'F.B.I.' to match documents containing 'FBI', and vice-versa. But it is counter-intuitive that searching for the constituents of a hyphenated word won't necessarily find posts containing that word.

Fixing this seemed like it might involve a lot of work. I was happy to discover that the architecture of search module allowed me to enable the behaviour I wanted for hyphens, without breaking the nice default behaviour for such things as acronyms, with a half-dozen lines of code.

The key doing this is the search_preprocess() function, which invokes the hook_search_preprocess() hook in all modules that implement it. The hook takes a string (initially the text to be indexed) and returns a transformed version of the text. Fortunately, this hook is invoked before hyphens and such are stripped out. It is possible to imagine many applications of this kind of transformation, but it is easy to see that we can use it to append the individual words constituting a hyphenated compound to the text.

read more
Categories: hyphenation · search

Drupal OpenSearch Aggregator

Steven - December 16, 2006 - 12:01pm

I just committed a working version of my new OpenSearch Aggregator module to Drupal Contrib CVS.

OpenSearch is a standard by Amazon which allows you to share search results through RSS. The feeds are valid RSS, they just contain extra meta-data for searching. So, you can use OpenSearch with any RSS reader to set up feeds to track tags or keywords for example.

We also have an OpenSearch client module that provides these feeds, and I just updated it to send search relevance information along. So, you could set up 5 Drupal sites with OpenSearch module, and a sixth site with the OpenSearch aggregator. Now, you can search all 5 sites simultaneously, and get a single, ordered list of global results.

However, because OpenSearch is an open standard, it can be used for anything. Amazon's A9 search already offers media search for example. The possibilities really are endless.

The best part? The OpenSearch Aggregator presents its results through the normal search system. So, if you install the OpenSearch module on top of this, you automatically provide OpenSearch feeds for the aggregated search. In other words, Drupal is now a complete OpenSearch processing suite! There is no other CMS out there that can claim this.

More info is on the Drupal.org project page.

[cross-posted from acko.net]

jQuery Menu Scout

Steven - December 7, 2006 - 11:49am

Out of a whacky conversation on IRC comes the latest treat for Drupal 5.0.

The new administration section is nice, but it's a big adjustment for 4.7 users. It's not immediately obvious where to go to find a certain option. Wouldn't it be handy if you could find any administration page with a couple of keystrokes? Something like Apple Spotlight?

Today's usability special: a nice slice of jQuery with some search module on the side, sprinkled with menu magic and topped off with some sexy CSS. Feast your eyes on this:

jQuery/Search module powered menu scout.
(MPEG-4 movie)

I still have some kinks to work out, so expect a reviewable patch in a day or two...

(cross posted from my personal blog)

Categories: administration · css · drupal · drupal 5 · jquery · menu · search · Spotlight
XML feed