[Zope] Search a Catalog in Python
Andre Meyer
a.meyer at hccnet.nl
Sun Mar 14 04:07:19 EST 2004
Hi Andreas
Sorry for making a mess out of this! It appeared that my mail didn't get
sent yesterday and now it is on the list multiple times.
Another mistake of mine: I was searching for an item that was not
indexed... the result was that all items got returned.
In fact, my version with search() does work now and I know why after
having looked deep into UnIndex.py (_apply_index()).
But, is it the case that searchResults() is preferred to search() ? Why?
Sorry for the trouble and thanks for the help
Andre
PS My current version is:
request = {'id':item} # NB 'id' must be a key in at least one of
the indexes of the catalog
obj = self.Catalog.search(request)
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 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