RE: [Zope] ZCatalog Question - Seach on numbers, not letters
ZCatalog tends to have problems searching on numeric data. The code below converts characters that give zcat trouble to characters that don't, and back again. Drop this script into your extensions directory, and create a couple of external methods (I like catalog_quote & catalog_unquote, but feel free to be creative). Call them when you need them. Disclaimer: I didn't write this code, and don't remember where I found it, but it works nicely. from string import strip, split, join, uppercase, lowercase, find bad_characters=(('.'), ('+'), ('-'), (';'), (':'), ('&'), ('%'), ('#'), ('@'), ('$'), ('0'), ('1'), ('2'), ('3'), ('4'), ('5'), ('6'), ('7'), ('8'), ('9')) def catalog_quote(self, ascii): text = str(ascii) for re in bad_characters: if find(text, re) >= 0: text=join(split(text,re),ordinalize(re)) return text def ordinalize(letter): number = ord(letter) number_string = str(number) myletters = lowercase[-5:] + uppercase[-10:] converted = '' for character in number_string: converted = converted + myletters[int(character)] return converted + 'g' def catalog_unquote(self, ascii): text = str(ascii) for un in bad_characters: if find(text, ordinalize(un)) >= 0: text=join(split(text,ordinalize(un)),un) return text Hope this helps, Aaron Gillette abg@comco-inc.com
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of complaw@hal-pc.org Sent: Thursday, May 16, 2002 2:00 PM To: zope@zope.org Subject: [Zope] ZCatalog Question - Seach on numbers, not letters
A set of DTML Documents have a field containing telephone numbers. The users want to be able to search, for example, for all telephone numbers starting with a given area code (like 713). The field has been indexed using a TextIndex, a FieldIndex, and a KeywordIndex. In each case, the index was set up and the index process was run. For the TextIndex case, no objects were (re)indexed and the subsequent search results were always empty. For the case the KeywordIndex and the FieldIndex, only exact matches were returned.
Is there a way to index something like a telephone number (i.e., no letters) so that they return valid results on -partial- input?
Thanks in advance,
Ron
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (1)
-
abg@comco-inc.com