I am looking for information on how to set up my site to search for partial words.

For example:

If I have a piece of content named Japanese SteakHouse.

This should come up if you search for Japan, Steak or House.

How can this be done?

I have the normal Drupal search module and then also the Porterstemmer module installed.

What else do I need to do?

Comments

nevets’s picture

subscribing

dadofgage’s picture

bump

dadofgage’s picture

I can hardly believe that no one has done this or figured this out.

So, I finally got this working and had to change 3 lines of code to get the results I wanted:

The first line is the previous line, the second line is the new line:

# $query2 = substr(str_repeat("i.word = '%s' OR ", count($arguments2)), 0, -4);
$query2 = substr(str_repeat("i.word like '%%%s%%' OR ", count($arguments2)), 0, -4);

# return array("d.data ". ($not ? 'NOT ' : '') ."LIKE '%% %s %%'", $count);
return array("d.data ". ($not ? 'NOT ' : '') ."LIKE '%%%s%%'", $num_new_scores, $num_valid_words);

# $boundary = '(?:(?<=['. PREG_CLASS_SEARCH_EXCLUDE . PREG_CLASS_CJK .'])|(?=['.REG_CLASS_SEARCH_EXCLUDE . PREG_CLASS_CJK .']))';
$boundary = '';

I hope this helps someone else that is trying to get this to work with version 5.x of Drupal.

Good luck.

martysteer’s picture

This patch works for me on D6.x.

Though the lines to patch are a bit further down in the file.

daniel wentsch’s picture

Thanks a lot for that snippet. Really helped me out, works perfectly on Drupal 6.10.

sharlak’s picture

Thank you very much for this patch, this is exactly what I needed. I know that this kind of search could be a performance killer feature... but wouldn't be interesting to include it in search module, setting a configuration parameter to choose whether you want partial word search or not?

davehci’s picture

What file needs editing?

sharlak’s picture

You need to edit search.module. As a Drupal core functionality is modified I recommend you to copy search module from drupal/modules/search to drupal/sites/all/modules/patched and make the changes there.

rooby’s picture

For a drupal 7 version of this see - #498752-19: Partial word search for Drupal 7
And for support for the search filter and argument in views also see #1480594-5: Filter Search Terms partial matching

JayKayAu’s picture

What you're looking for is an N-Gram (http://en.wikipedia.org/wiki/N-gram) based search solution. I've just spent the past few hours trying to work this out, and so I'm writing notes here in the hope it helps someone in future...

There's a module which enables it for the core search here: http://drupal.org/project/fuzzysearch

Or for Search Lucene, you need the "DidYouMean" plugin: http://drupal.org/project/luceneapi_dym

Or for Apache Solr, (I think this is what you want): http://drupal.org/project/apachesolr_autocomplete

The Fuzzy Search module doesn't yet (as of March 2011) support Views Exposed Filters. Watch this space: #177368: Integration into views

If you need it on a Views Exposed Filter (as I did), copy the core Search module to your /sites/all/modules/ folder, and apply this patch: http://drupal.org/node/103548#comment-2791774

-----

There's a long thread about including this feature in core here: http://drupal.org/node/103548

It looks like it *may* make it into D8.

It didn't make it into D7 because there was a lot of faffing around and debate about performance and other methods of achieving the same thing.

(Which was in my profoundly humble opinion, a bit ridiculous, given the expectation that every normal human being and/or client on earth has that this feature exists by default. But I digress.)

So, hope that helps :)