changeset 2229:c1ef587208c0

Xapain: raise exception TypeError if Stemmer fails
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 29 May 2007 10:16:11 +0200
parents 3b2f654037da
children 48af49661497
files MoinMoin/search/Xapian.py
diffstat 1 files changed, 12 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/search/Xapian.py	Mon May 28 21:04:37 2007 +0200
+++ b/MoinMoin/search/Xapian.py	Tue May 29 10:16:11 2007 +0200
@@ -381,21 +381,6 @@
         except (OSError, IOError):
             pass
 
-    def verify_language(self, value):
-        """ Verifies if language is available for Stemming algorithms
-        @value: language code
-        """
-        from Stemmer import algorithms
-        stemmer_langs = algorithms()
-        from MoinMoin import i18n
-        langs = i18n.wikiLanguages().items()
-        langs.sort(lambda x, y: cmp(x[1]['x-language-in-english'], y[1]['x-language-in-english']))
-        for lang in langs:
-            if value == lang[0] and lang[1]['x-language-in-english'].lower() in stemmer_langs:
-                return True
-        if debug: request.log("%s (no stemming possible)" % (value,))
-        return False
-
     def _get_languages(self, page):
         """ Get language of a page and the language to stem it in
 
@@ -410,15 +395,18 @@
             lang = page.pi['language']
             # Stemmer(lang) has an exception bug if the language is not available
             # TypeError: exceptions must be strings, classes, or instances, not exceptions.KeyError
-            if self.verify_language(lang):
-                try:
-                    Stemmer(lang)
-                    # if there is no exception, lang is stemmable
-                    return (lang, lang)
-                except KeyError:
-                    # lang is not stemmable
-                    pass
-
+            try:
+                Stemmer(lang)
+                # if there is no exception, lang is stemmable
+                return (lang, lang)
+            except KeyError:
+                # lang is not stemmable
+                pass
+            except TypeError:
+                # Stemmer(lang) has an exception bug if the language is not available
+                # TypeError: exceptions must be strings, classes, or instances, 
+                pass
+    
         if not lang:
             # no lang found at all.. fallback to default language
             lang = default_lang