Hi, I've been attempting (unsuccessfully) for a couple of days now to implement a simple search facility on a Zope based intranet I inherited responsibility for. (Forgive me if this is a really basic question, I'm much more comfortable with PHP and MySQL). After going around in numerous circles and butting my head up against a wall almost constantly I've finally worked out that: a) The text to search on is in a Gadfly database AND b) Gadfly databases don't support the SQL "LIKE" operator The manual says something about using python and regular expressions or something instead of "LIKE" but it's enough of a battle for me puzzling out this Zope stuff let alone learning some Python too... Oh, and the reason I decided to try the SQL route was because Z Catalog didn't seem to store any useful information that I wanted to search on. It (understandably) only catalogued information ABOUT the Z SQL Method, not information IN the Z SQL Method. Can anyone help me with a way to search a Gadfly database: either using SQL, Z Catalog or some other method. Thanks in advance! Matthew
Matthew Lindfield Seager wrote: [...]
The manual says something about using python and regular expressions or something instead of "LIKE" but it's enough of a battle for me puzzling out this Zope stuff let alone learning some Python too...
a) Consider a Gadfly table User(ID, Name, ...) and you want to search for names in it. b) Make a Z SQL called Names, which retrieves the Primary Key and the field where you want to search, like this: Select ID, Name from User c) Have a form with an input field called 'name' and a submit button calling findName. d) Create a Python Script called findName with code like this: _________ rs = container.qryNames() # retrieve ALL the records ids = [] # make an empty list for rec in rs: # loop over all the records if rec.NAME.find(name) > -1: # found a sub-string in the current record? ids.append(rec.STAFFID) # append it to the list return ids __________ AND an argument called 'name' That's it. You can use the list with ids in a zope page template or a dtml page to show, e.g., the full records. Look for 'sequences' and strings in Python docs. You can also use list comprehension instead of the loop. Probably faster. HTH, Fernando
Matthew Lindfield Seager wrote at 2003-3-26 16:43 +1100:
... After going around in numerous circles and butting my head up against a wall almost constantly I've finally worked out that: a) The text to search on is in a Gadfly database AND b) Gadfly databases don't support the SQL "LIKE" operator
Use an external database (Postgres or MySQL) that supports "LIKE". Dieter
participants (3)
-
Dieter Maurer -
Fernando Martins -
Matthew Lindfield Seager