[Zope] Search a Catalog in Python
Andre Meyer
meyer at acm.org
Sat Mar 13 13:12:15 EST 2004
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']})
What is wrong here? I feel very stupid again. Any help is appreciated!
Thanks and kind regards
Andre
More information about the Zope
mailing list