RE: [Zope] ZCatalog / Zsearch dates?
-----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
Michel Pelletier wrote:
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>
Ah, that makes sense! Thanks. (although, I believe it's ZopeTime not DateTime? At least...ZopeTime works but not DateTime - I get a keyError otherwise)
A very useful example of using dates can be seen on the zope.org advanced search page:
<snip> Yes indeed. It's now saved for later reference :-) (The following is not a problem, it's a solution for others who might have had a similar problem) However, I came across another "problem". Now that I'm passing in a ZopeTime object, Zope will insist on _getting_ a ZopeTime object. Let me clarify. I have a search form such: Title: [textfield] Date: [textfield] Text/keyword: [textfield] Now, if I leave the date field blank, I get an error because it's expecting a ZopeTime object. There are cases where you'll want to make a search by one or more items that you know. You might not know the date of the item, for instance. So how do I get around this error? (This problem did not surface if only strings were used.) You need to do: <dtml-if date> <dtml-in "Catalog(date=ZopeTime(date))"> ... </dtml-in> <dtml-else> <dtml-in Catalog> ... </dtml-in> <dtml-if> The first one is the "special" case where a date is specified and the second one for when it's not. This avoids the Error message for not passing in the ZopeTime object. Simple but it got me stumped for a bit... -- ----------------------------------------- Kuraiken - Python fanatic. ----------------------------------------- Python. Try it. It'll swallow you whole! -----------------------------------------
participants (2)
-
Kuraiken -
Michel Pelletier