On 12/6/05, Frank Burkhardt <[EMAIL PROTECTED]> wrote:
> Hi,
> after adding a "Unique Id utility", "Catalog" and some field + text indices
> I successfully added documents which seem to be added to the catalog
> (as shown in the catalog's "Advanced"-tab).
> However I've got two question now:
> 1. How do I search the catalog?

Querying the catalog directly is kindof a pain right now, as the
indexes have their own 'query' syntax. I'd recommend checking out
'hurry.query' which makes building queries easier:


But to query directly, you can basically do this in a view:

catalog = zapi.getUtility(ICatalog, 'catalog', self.context)
results = self._results = catalog.searchResults(textindexname='text to
search for', fieldindexname=('low value', 'high value'))

and so on, with 'textindexname' and 'fieldindexname' being the names
of the indexes you're searching for. For field indexes, you have to
specify a 'low' and 'high' value in the tuple. This surprised me when
I was doing catalog work a few months ago before we started using
hurry.query - I thought I could do a search like ``section='winter'``
to get all documents in the 'winter' section of the site. That worked
fine. But when we added 'summer' to the site and I did
``section='summer'``, winter documents showed up too! What happened is
that when only one value is passed into the field index for querying,
it's thought that the high value is open. Since 'winter' > 'summer',
the winter documents were being returned in my summer query, but not
the other way around. So a field index query is a range. If you want
items that match a single value like I did, you have to do something
like ``section=('summer', 'summer')``.

With 'hurry.query' you can build complex queries more easily.

> 2. Documents are added to the index only when they are added to the ZODB.
>    Is there a Way to "scan" the entire ZODB to index all objects
>    matching the indices interface constraints?

On the 'Advanced' tab for the catalog in the default skin(s) there is
a 'Reindex' button which will rebuild all of the indices based on
their configuration.
Zope3-users mailing list

Reply via email to