[Zope] Help with Search in Zope

Oleg Broytmann Oleg Broytmann <phd@phd.fep.ru>
Tue, 10 Apr 2001 18:32:27 +0400 (MSD)


Hello!

> The ZCatalog doesn't generally index relational data.  Its usually used to
> index things in the ZODB.

   There are so many questions and problems and deficiencies about
ZCatalog. Think for example I want to index a site on
bobobase_modification_time and search for date ranges. Impossible! ZCatalog
does not have ranges.
   Recently added textindex_operator allows to use "and", "near", "andnot",
"or" operators, but it is insufficient. I can only use the operator for one
index. What if I want to search for
   "title LIKE '%ZOPE% OR body LIKE '%python%'"? Alas!
Developing special SQL-like language for ZCatalog? It is hard. What than?

   A crazy idea sprang into my mind. What if I, the site programmer, could
provide a callback function, and ZCatalog will call the function for every
index? Then I can code such simple or complex search as I need. Examples:

   <dtml-in "Catalog(indicies=['id', 'titile', 'time'], callback=mySearch)">

def mySearch(id, titile, time):
   if re.search("ZOPE", id): return 1
   if re.search("python", title, re.I): return 1
   if "2000/01/01" <= time <= "2000/12/31": return 1
   return 0

Let the function return 1 for objects that correspond the serach criteria,
0 for failed objects, and raise StopSearch exception if it need to stop
search immediatly.

Oleg.
----
     Oleg Broytmann     http://www.zope.org/Members/phd/     phd@phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.