[Zope] Help with Z Search Interface and ranges

Jeff Rush Jeff Rush" <jrush@timecastle.net
Fri, 19 Nov 99 03:30:37 -0500


On Thu, 18 Nov 1999 08:35:43 -0600, Willie Peloquin wrote:

>I really don't understand how these pages are working.
>I have appended the search and report DTML that was generated in a small
>sample database I created.

<snip>

>How do the items in the form get transferred to
>the 'report' dtml, via the URL? Does the report parse the URL to determine
>the search parameters, or is there a hidden method that I don't know about.

The items in the form get stuffed into the REQUEST structure automatically
via the normal HTTP post/Zope process.  Then you can pass the REQUEST structure
into the searchResults() method and the ZCatalog searchResults() method
will match up any attributes in REQUEST with the set of columns you chose to index
on when you created the HouseCatalog, and where there is a match in name, it
will use it.  This -can- be dangerous if you use generic-sounding columns in your
catalog, as it can pick up unintended search criteria using items that already
exist in REQUEST.  You're safe with 'price' and such.  There is also some risk with
empty fields, where field=(empty) means match all such items, not ignore the field.

In your case you would change the line in your example below:

    <!--#in HouseCatalog size=50 start=query_start-->

into something like:

    <!--#in "HouseCatalog.searchResults(REQUEST=REQUEST)" size=50 start=query_start-->

if your search criteria is specified via attributes in the REQUEST structure, say using the
REQUEST.set type of arrangement or if you prefer explicit specification of such, like:

    <!--#in "HouseCatalog.searchResults(
                 price=[10000, 15000], price_usage='range:min:max',
                 state=['TX', 'MI', 'CA'],
                 beds=4)"
                 size=50 start=query_start-->

or even:

    <!--#in "HouseCatalog.searchResults(
                 price=REQUEST.price, price_usage='range:min:max',
                 state=REQUEST.state,
                 beds=REQUEST.beds)"
                 size=50 start=query_start-->

This will search for a house in the specified price range -AND- if it
resides in -ONE OF- the specified states.

This form gives you more control albeit at the cost of more complex code.

Note that within the in-loop, as a performance speedup by ZCatalog,
you will have access to those catalog fields that you specified in your
metadata schema when you created the catalog, *NOT* those fields you
indexed on.  You can also retrieve the item itself, via the
HouseCatalog.getobject(data_record_id_) method, or just it's URL,
via the HouseCatalog.getpath(data_record_id_) method.

__________________________________________________
Jeff Rush <jrush@taupro.com>    Tau Productions Inc.
Linux/Python/Zope Consultant    http://www.taupro.com