first pass at stop word support for sorting
authorartunit <artunit@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 26 Nov 2010 19:52:06 +0000 (19:52 +0000)
committerartunit <artunit@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 26 Nov 2010 19:52:06 +0000 (19:52 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1090 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/syrup/models.py

index 594ff8a..a3bb5ba 100644 (file)
@@ -265,15 +265,31 @@ class Site(BaseModel):
         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):