[Zope] Search a Catalog in Python
Dragos Chirila
d.chirila at finsiel.ro
Mon Mar 15 04:10:42 EST 2004
Hi
I am doing something similarly.
def __searchCatalog(self, p_criteria):
"""Search catalog"""
return self.__catalog(p_criteria)
This returns a list of mybrains objects.
def __getFoundObjects(self, p_list):
"""gets objects from catalog results"""
return map(self.__catalog.getobject, map(getattr, p_list,
('data_record_id_',)*len(p_list)))
It gets a list of mybrains objects and returns a list of zope objects.
So, to search the catalog (in my case the __catalog is the ZCatalog
instance):
results = self.__getFoundObjects(self.__catalog(filter))
The filter mut be a dictionary, something like: {'meta_type': 'File'}.
I think that you must write like:
obj=self.Catalog('id':item}
if you want to search by id.
Hope this will help
Dragos
> 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(id={'query':[item]})
>
>
> 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