From d0b353f04f263d990bd12e800e0dbf4e7e54321f Mon Sep 17 00:00:00 2001 From: artunit Date: Fri, 26 Nov 2010 19:52:06 +0000 Subject: [PATCH] first pass at stop word support for sorting git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1090 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/models.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 594ff8a..a3bb5ba 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -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): -- 2.11.0