[Zope] Search a Catalog in Python

Andreas Jung andreas at andreas-jung.com
Sun Mar 14 02:48:48 EST 2004


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 at 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']})
>
>
> What is wrong here? I feel very stupid again. Any help is appreciated!
>
> Thanks and kind regards
> Andre
>
>
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )







More information about the Zope mailing list