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	6 Jul 2009 22:31:59 -0000
@@ -38,6 +38,47 @@
 }
 
 /**
+ * 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 potential match. Find the end of the word we
+  // actually matched, so it can be highlighted (making sure it's a real match
+  // for our key).
+  $newmatch = array();
+  foreach( $match as $item) {
+  	$pos = $match[0][1];
+  	if (preg_match('/' . $boundary . '/iu', $text, $newmatch, PREG_OFFSET_CAPTURE,
+        $pos + strlen($key))) {
+      $keyfound = substr($text, $pos, $newmatch[0][1] - $pos);
+      $foundstem = Stem( $key );
+      replace( $foundstem, 'e', '' ) OR replace( $foundstem, 'y', '' );
+
+      if ($foundstem == $key) {
+      	return array('where' => $pos, 'keyword' => $keyfound);
+      }
+    }
+  }
+
+  // If we get here, none of the potential matches worked out.
+  return FALSE; 
+}
+
+/**
 * Regex for matching a consonant
 */
 define('regex_consonant', '(?:[bcdfghjklmnpqrstvwxz]|(?<=[aeiou])y|^y)');
