Index: porterstemmer.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/porterstemmer/porterstemmer.module,v
retrieving revision 1.1
diff -u -r1.1 porterstemmer.module
--- porterstemmer.module	17 Dec 2005 22:43:02 -0000	1.1
+++ porterstemmer.module	2 Jul 2009 22:34:18 -0000
@@ -38,6 +38,36 @@
 }
 
 /**
+ * Implementation of hook_search_excerpt_match().
+ */
+function porterstemmer_search_excerpt_match( $key, $text, $offset, $boundary) {
+  // Stem the keyword down to its root form.
+  $key = Stem($key);
+  // In many cases, the root word is a substring of the full word, but not
+  // all. The cases where it is not have the root ending in e or y, so drop
+  // the e or y at the end of the root.
+  replace( $key, 'e', '' ) OR replace( $key, 'y', '' );
+
+  // Look for this modified key at the start of a word.
+
+  $match = array();
+  if (!preg_match('/'. $boundary . $key . '/iu', $text, $match, PREG_OFFSET_CAPTURE, $offset)) {
+    // didn't match our modified key.
+    return FALSE;
+  }
+
+  // If we get here, we have a match. Find the end of the word we
+  // actually matched, so it can be highlighted.
+  $pos = $match[0][1];
+  if (preg_match('/' . $boundary . '/iu', $text, $match, PREG_OFFSET_CAPTURE,
+      $pos + strlen($key))) {
+    $keyfound = substr($text, $pos, $match[0][1] - $pos);
+  }
+
+  return array($pos, $keyfound);
+}
+
+/**
 * Regex for matching a consonant
 */
 define('regex_consonant', '(?:[bcdfghjklmnpqrstvwxz]|(?<=[aeiou])y|^y)');
