[Zope] Need ZCatalog help

Martijn Pieters mj@antraciet.nl
Fri, 10 Sep 1999 12:24:13 +0200


At 04:26 10/09/99 , John Goerzen wrote:
>First.  I created a ZClass in my own Application with my Events
>class.  Do I need to delete it and recreate it so that it lists
>ClassAware as one of its meta types?

Yes, make sure that CatalogAware is the first object in the list! This is 
important.


>When a class is ClassAware, how does it know into which catalog new
>items should go?  I haven't been able to make the thing update
>catalogs automatically.

If it is the first item, it'll catalog itself by default in the catalog 
named, surprisingly, 'Catalog'. This default can be changed by calling 
setting default_catalog on the object, or calling 
'manage_editCatalogerForm' on the object for a visual interface (in a browser).


>What is the purpose of using the Contents tab of a ZCatalog to
>actually add items inside it?  What are the pros/cons of doing this?
>Why are these objects not automatically cataloged?

Those items that are not CatalogAware can only be added and removed through 
this tab. If you want to add objects using the find option, then all 
objects in you ODB will be woken up to do a brute force search for the 
objects that come up to your criteria.


>Where can I find a reference on the syntax of searching a catalog?

You call searchResults on the catalog object, and you specify either a 
dictionary of search criteria, or you put the criteria in the REQUEST object:

<dtml-call "REQUEST.set('body_text', '"Martijn Pieters" and not "Martijn 
Faassen"')">
<dtml-in searchResults>..</dtml-in>


<dtml-in "searchResults({'body_text': '"Martijn Pieters" and not "Martijn 
Faassen"'})">..</dtml-in>

The curly braces are python syntax: they create a dictionary. Each "string: 
value" combination is an entry into the dictionary. In the line above I 
asked for a search in the TextIndex named 'body_text'.

You can specify search terms for every index in your catalogue, and you'll 
only get those objects that match _all_ the specified criteria.

 From the source I can infer the following:

Within a TextIndex, one can supply a query string that uses boolean search 
terms.

Supported are: 'and', 'or', 'andnot' (or 'and not'), '...' (meaning near), 
phrases (surrounded by "quotation marks"), and grouping (using parens).

In a FieldIndex, you can just simply specify a list of values (or just one 
value) that all returned objects should have, or you could specify a 
fieldname + '_usage' parameter. It is a string that specifies how to treat 
values found in the search list, and has the following format:

'range[:min][:max]': the search parameter for this field is a list of one 
or more elements. If :min is specified, then the lowest of these elements 
is the  minimal value for this field. And if :max is used, the highest of 
these elements is the maximal value for this field. All objects that fall 
within this range should be returned. This means that if you only specify a 
:max parameter, you get all objects whose attribute indexed by this field 
is lower then the value you supplied.

So, if you have an index on an integer value, called 'level', and you ask 
for {'level': 10, 'level_usage': 'range:max'} you'll get all objects whose 
'level' property is 10 or lower. If I only ask for {'level': 10} I only get 
objects whose level is exactly 10. Note that if I use {'level': (1, 2, 3, 
4), 'level_usage': 'range:min:max'} I'll get all objects with a level from 
1 to 4.

Next to specifying fields and their search criteria, I can also influence 
the  order of the returned objects with the 'sort-on' and 'sort-order' 
parameters.

If you specify 'sort-on', it should be the name of the index on which the 
results will be sorted. Note that at this moment, due to a bug you 
cannot  sort on a FieldIndex!

If you specify 'sort-order' and its value is either 'reverse' or 
'descending', the result list will be reversed.

Hope this helps.


--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------