[open-ils-commits] r1090 - servres/trunk/conifer/syrup (artunit)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Nov 26 14:52:11 EST 2010


Author: artunit
Date: 2010-11-26 14:52:06 -0500 (Fri, 26 Nov 2010)
New Revision: 1090

Modified:
   servres/trunk/conifer/syrup/models.py
Log:
first pass at stop word support for sorting

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2010-11-25 20:01:27 UTC (rev 1089)
+++ servres/trunk/conifer/syrup/models.py	2010-11-26 19:52:06 UTC (rev 1090)
@@ -265,15 +265,31 @@
         return either a single (Item, [Item]) pair, where Item is the
         subtree element, or None if there is no match.
         """
+
+        def sort_title(item):
+            """First cut of a stop words routine."""
+            # TODO: this needs to either be in its own file or in settings
+            stopwords = '''
+			a
+			an
+                        that
+			there
+                        the
+                        this
+                '''.split()
+
+            normal_text = [t for t in item.split() if t.lower() not in stopwords]
+            return  " ".join(normal_text)
+
         items = self.items()
         # make a node-lookup table
         dct = {}
         for item in items:
             dct.setdefault(item.parent_heading, []).append(item)
         for lst in dct.values():
-            # TODO: what's the sort order?
+            # TODO: what's the sort order? - art weighing in on normalized title
             lst.sort(key=lambda item: (item.item_type=='HEADING',
-                                       item.title)) # sort in place
+                                       sort_title(item.title))) # sort in place
         # walk the tree
         out = []
         def walk(parent, accum):



More information about the open-ils-commits mailing list