[Zope] Zcatalog & KeywordIndex
Dieter Maurer
dieter@handshake.de
Wed, 21 May 2003 20:47:08 +0200
John Toews wrote at 2003-5-20 14:10 -0500:
> I'm having some difficulties using my Zcatalog & my KeywordIndex within
> that catalog.
>
> I have a subdirectory of different files, each with a property called
> "repo_keywords". I created a KeywordIndex called "repo_keywords". When I
> search using this, I must enter the exact text within the repo_keywords
> property (instead of just one word or a phrase).
As Andreas already wrote, phrases or substrings are not supported by
"KeywordIndex".
A "KeywordIndex" interprets the value as a sequence and indexes
the object under each element in the sequence.
If the document's value for the index is, e.g., "('red', 'green', 'blue')",
then the document is indexed under "red", "green" and "blue"
and can be found under any of these terms.
In
<http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
you find an alternative (to the Zope Book) description of
ZCatalog and its indexes. Not sure, whether you will find
it more useful.
> Also, when I add a new file, I have to re-find everything in my
> Zcatalog, update catalog doesn't seem to work? (Win32, Zope 2.6.1,
> Python 2.1.3)
The is explained in the above reference:
The integration between Zope and ZCatalog is really loose (almost
non existant!).
You might look for CMF to get tighter integration.
"ZCatalog" provides a method "catalog_object" which can be
used to catalog single objects (e.g. after you added a new
object or made some modifications).
When you build your own objects (either through a ZClass
or in a Python based product), you can inherit from
"CatalogPathAware" ("CatalogAware" for "ZClass").
This handles automatic cataloguing/uncataloguing when
such objects are created/deleted (provided the catalog
is named "Catalog"). Even then, you must explicitely request
recataloguing after modifications.
"updateCatalog" recatalogs all objects, ZCatalog already has
catalogued. This means, it does not work for new objects...
As "updateCatalog" is very expensive (one many objects are
catalogued), you definitely do not want to use it after
any modification ;-)
Dieter