--- porterstemmer.module	2010-11-11 01:12:18.000000000 +0100
+++ porterstemmer.module	2011-08-16 14:17:29.000000000 +0200
@@ -8,6 +8,124 @@
  * by Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com
  */
 
+
+// global variables to hold lists of words
+$porterstemmer_stopwords = array();
+$porterstemmer_exceptions = array();
+
+
+/*
+ * get list of stop words from database.
+ * Local copy of stemmer_api_stopwords_read
+ */
+function porterstemmer_stopwords_read($module) {
+  $stopwords = variable_get($module . '_stopwords','');
+  if ( empty($stopwords) ) {
+        drupal_set_message('porterstemmer_stopwords_read: list is empty');
+    return array();
+  }
+  return unserialize($stopwords);
+}
+
+
+/*
+ * get list of exceptions from database
+ * Local copy of stemmer_api_exceptions_read
+ */
+function porterstemmer_exceptions_read($module) {
+  $exceptions = variable_get($module . '_exceptions','');
+  if ( empty($exceptions) ) {
+        $excpt = _porterstemmer_exceptions_init();
+        if ( function_exists('stemmer_api_exceptions_store') ) {
+            stemmer_api_exceptions_store($excpt,'porterstemmer');
+        }
+       return $excpt;
+  }
+  return unserialize($exceptions);
+}
+
+
+
+/*
+ * implementation of hook_init
+ * initialize variables on each bootstrap
+ */
+function porterstemmer_init() {
+  global $porterstemmer_stopwords;
+  global $porterstemmer_exceptions;
+
+  $porterstemmer_stopwords = porterstemmer_stopwords_read('porterstemmer');
+  $porterstemmer_exceptions = porterstemmer_exceptions_read('porterstemmer');
+}
+
+
+/*
+ * initialize list of "exceptions" words
+ */
+function _porterstemmer_exceptions_init() {
+  // Special cases for stemming. Don't add anything in this list that
+  // is shorter than the minimum allowed length!
+  $excp = array(
+    'skis' => 'ski',
+    'skies' => 'sky',
+    'dying' => 'die',
+    'lying' => 'lie',
+    'tying' => 'tie',
+    'idly' => 'idl',
+    'gently' => 'gentl',
+    'ugly' => 'ugli',
+    'early' => 'earli',
+    'only' => 'onli',
+    'singly' => 'singl',
+    'sky' => 'sky',
+    'news' => 'news',
+    'howe' => 'howe',
+    'atlas' => 'atlas',
+    'cosmos' => 'cosmos',
+    'bias' => 'bias',
+    'andes' => 'andes',
+	// invariant
+    'inning' => 'inning',
+    'outing' => 'outing',
+    'canning' => 'canning',
+    'herring' => 'herring',
+    'earring' => 'earring',
+    'proceed' => 'proceed',
+    'exceed' => 'exceed',
+    'succeed' => 'succeed',
+  );
+  return $excp;
+}
+
+
+/**
+ * Implementation of hook_menu().
+ */
+function porterstemmer_menu() {
+  $items = array();
+  $items['admin/settings/porterstemmer'] = array(
+    'title' => 'Porter stemmer',
+    'description' => 'Search by word stemms',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('porterstemmer_settings'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  return $items;
+}
+
+
+/*
+ *
+ */
+function porterstemmer_settings()
+{ return array();
+}
+
+
+/******************************************************************************************/
+
 /**
  * Implements hook_search_preprocess().
  *
@@ -696,32 +814,11 @@
  *   TRUE if it is time to stop stemming, FALSE to continue.
  */
 function porterstemmer_exception1(&$word) {
-  // Special cases for stemming. Don't add anything in this list that
-  // is shorter than the minimum allowed length!
-  $repl = array(
-    'skis' => 'ski',
-    'skies' => 'sky',
-    'dying' => 'die',
-    'lying' => 'lie',
-    'tying' => 'tie',
-    'idly' => 'idl',
-    'gently' => 'gentl',
-    'ugly' => 'ugli',
-    'early' => 'earli',
-    'only' => 'onli',
-    'singly' => 'singl',
-    'sky' => 'sky',
-    'news' => 'news',
-    'howe' => 'howe',
-    'atlas' => 'atlas',
-    'cosmos' => 'cosmos',
-    'bias' => 'bias',
-    'andes' => 'andes',
-  );
+  global $porterstemmer_exceptions;
 
   // If our word is in that list, we're done.
-  if ( isset( $repl[ $word ])) {
-    $word = $repl[ $word ];
+  if ( isset( $porterstemmer_exceptions[ $word ])) {
+    $word = $porterstemmer_exceptions[ $word ];
     return TRUE;
   }
 
@@ -737,19 +834,9 @@
  *   TRUE if it is time to stop stemming, FALSE to continue.
  */
 function porterstemmer_exception2(&$word) {
-  // The following words are to be left invariant.
-  $repl = array(
-    'inning' => 1,
-    'outing' => 1,
-    'canning' => 1,
-    'herring' => 1,
-    'earring' => 1,
-    'proceed' => 1,
-    'exceed' => 1,
-    'succeed' => 1,
-  );
+  global $porterstemmer_exceptions;
 
-  if ( isset( $repl[ $word ])) {
+  if ( isset( $porterstemmer_exceptions[ $word ])) {
     return TRUE;
   }
 
