[Zope] ZCatalog / Zsearch dates?

Michel Pelletier michel@digicool.com
Wed, 29 Sep 1999 13:00:38 -0400


> -----Original Message-----
> From: Kuraiken [mailto:arashi1@pd.jaring.my]
> Sent: Tuesday, September 28, 1999 6:18 PM
> To: ML - Zope
> Subject: [Zope] ZCatalog / Zsearch dates?
> 
> 
> Hi all,
> 
> I've come across another problem about searching. A ZCLass 
> has a date property.
> (yyyy/mm/dd) The instances stores the dates no prblem. The 
> catalog also stores
> it in the meta-data table. I've also got it in the index 
> list. (tried both
> textIndex and fieldIndex) - rebuilt the search interfaces both times.
> 
> Even though in the "search" dtml, the field "date" appears, 
> filling this field
> for a search turn up zero matches every time! Even though 
> there are clearly
> instances with those dates stored - (searching for items 
> while leaving the
> "date" field empty indicates that the date _is_ stored by the catalog.
> 
> How do I get searches for dates to work? (date type in the 
> class property sheet)
> Could it be a bug in the search interface methods? I'm using 
> the generated
> methods...is there something I need to add?

Are you passing the query a string or a DateTime object?  If you are
doing this:

  <form action="report">
    <input name="date">
    <input type=submit value="submit">
  </form>

into:

  <dtml-in Catalog>
   ...
  </dtml-in>

Then you will get no results.  This is because the 'date' index is
storing DateTime objects, NOT strings.  To get a result, you will need
to pass the Catalog a query that contains an instanciated DateTime
object:

  <dtml-in "Catalog(date=DateTime(date))">
    ...
  </dtml-in>

A very useful example of using dates can be seen on the zope.org
advanced search page:

<input type="hidden" name="date_usage" value="range:min">
  <select name="date:date">
    <option value="<!--#var "ZopeTime(0)" -->">Ever</option> 
    <option value="<!--#var "ZopeTime() - 1" -->">Yesterday</option>
    <option value="<!--#var "ZopeTime() - 7" -->">Last Week</option>
    <option value="<!--#var "ZopeTime() - 30" -->">Last Month</option>
    <option value="<!--#var "ZopeTime() - 365" -->">Last Year</option>
  <!--#if "_.hasattr(AUTHENTICATED_USER,'prev_visit')"-->
   <option value="<!--#var "AUTHENTICATED_USER.prev_visit"-->">Last
Visit (<!--#var "AUTHENTICATED_USER.prev_visit" fmt=Date-->)</option>  
  <!--#/if-->
  </select>

This uses a hidden form element (date_usage) to tell the Catalog to do a
range search on the date index.

See: http://www.zope.org/SiteIndex/searchForm/view_source

-Michel