Fwd: Re: [Zope] Search a Catalog in Python
-----Original Message----- From: "Richard Jennings" <rjennings@stradefi.com> To: Andreas Jung <andreas@andreas-jung.com> Date: Sun, 14 Mar 2004 10:48:28 +0100 Subject: Re: [Zope] Search a Catalog in Python On Sunday 14 March 2004 08:48, Andreas Jung wrote:
If there is something going wrtong than you should provide error messages and tracebacks. The only thing I see is the use of the search() method instead of searchResults().
-aj --On Samstag, 13. März 2004 19:12 Uhr +0100 Andre Meyer <meyer@acm.org>
wrote:
Dear Zopers
This time, I thought it should be simple, but I am struggling again: The idea was to search for items that have been catalogued successfully. In the Zope Book they describe how to do this using form and scripts. That works for me, too, but then I need to search in a regular Python program (An FS product). For this purpose, I found the ZCatalog.search method and gave it a try, but I cannot get it to work. It expects a dictionary, but what does that contain?
Here is what I have so far:
__init__(self, id, title, ...): ... # add a Catalog _catalog = ZCatalog('Catalog') # add Metadata fields for the Catalog _catalog.addColumn('id') _catalog.addColumn('title') _catalog.addColumn('icon')
# PathIndex _catalog.addIndex('path_index', 'PathIndex')
# ZCTextIndex (with the required Lexicon) class Extra: """ Just a dummy to build records for the Lexicon. """ pass extra = Extra() extra.index_type = 'Okapi BM25 Rank' extra.lexicon_id = 'Lexicon' _catalog._setObject('Lexicon', PLexicon('Lexicon', '', Splitter(), CaseNormalizer())) _catalog.addIndex('title', 'ZCTextIndex', extra)
# FieldIndex _catalog.addIndex('composer_first_name_index', 'FieldIndex', 'first_name') _catalog.addIndex('composer_last_name_index', 'FieldIndex', 'last_name') _catalog.addIndex('composer_year_of_birth_index', 'FieldIndex', 'year_of_birth')
self._setObject('Catalog', _catalog)
...
# all new items get catalogued (verified) and now # we should be able to search for them like this: def searchForAnItem(item) obj=self.Catalog.search(last_name_index={'query': ['Aaa']})
Hi, wouldn't presume to offer help, but I can show you what works for me: I have catalog, 'processRoles', containing several different field indexes to process role objects. To get the catalog entry for a specific role I do: result = self.processRoles({'entityId':roleId}) where roleId is index value. the result is 'None', an object or a list of objects having the index. These objects are 'mybrains' instances which behave like dictionaries with additional methods. HTH. <rant disclaimer='this is NOT aimed at anyone, just the state-of-the-art'> I work almost entirely with products and face the same lack of examples working with python. Casey Duncan seems to be the catalog guru and if he reads this perhaps he could point us poor mortals in the direction of some (any?) documentation which gives python programming introduction to catalog & ZCatalog. For me, trying to deduce the functionality of catalog from the source is like trying to deduce the appearance of a pyramid from a 1 ton block of sand stone. </rant> Richard Jennings -------------------------- 'Just a bloke doing a job he (mostly) enjoys'
participants (1)
-
Richard Jennings