[Zope] Help with Search in Zope (SQL data)
Ron Bickers
rbickers@logicetc.com
Tue, 10 Apr 2001 10:32:28 -0400
I recently did this with MySQL to integrate the books for sale into the
entire site search at socap.org. Here's what I did:
1) Create a ZSQL Method to pull out the fields you want to index. The field
names must be the same as the indexes/meta data you want to store. For
example, getBooksToCatalog contains the following:
SELECT Number, Title, concat(Description, Title, Author) as
PrincipiaSearchSource, 'Book' as meta_type, Number as id, Description as
summary FROM Books
(I use the meta_type 'Book' to show in the results that it's a Book, vs.
just another page on the site)
2) Create a Python Script (a DTML Method would do, but this code, so it
really belongs in a script) that calls catalog_object() for each record
returned by the ZSQL Method above. The parameters are a) the record object,
and b) the uid -- the path you want to be used as a URL for viewing the
record. For example
for book in container.getBooksToCatalog():
catalog.catalog_object(book,
'/Publications/getBook/'+book.Number+'/bookdetails.html')
"Test" the script and that will get the data into the catalog. When a
search matches, getURL() will return something like
http://www.socap.org/Publications/getBook/00123/bookdetails.html. This is
the URL that can be used to view the book.
getBook is a ZSQL Method that has the advanced "Allow simple direct
traversal" option set, and a single argument of Number (which is a string).
The method looks like this:
SELECT * FROM Books WHERE <dtml-sqltest number column="Number" type=nb>
bookdetails.html is a DTML Method that displays the record returned by
getBook.
It's really quite simple once you get the gist. Using the above principles,
you can get almost anything into the catalog. I also have some articles
that are listed and summarized in MySQL and have associated PDF files in the
file system. I use a similar method, but I also have a class defined in
Extensions that is used by the ZSQL Method. The class defines
PrincipiaSearchSource as the text of its PDF file (actually, of the
converted text file). This gets me the source of the article in the
catalog, and result URLs that point to the article summary page where it can
be ordered or viewed as a PDF online.
One important down side to note is that if you do an 'Update Catalog' in the
ZCatalog Advanced tab, you'll mess up the catalog because it will try to
suck data based on the uid, not from the database as you intend. Because of
this, it's best to maintain a script (or several) that can be run to update
the data.
I hope this helps. Anyone interested in a more complete How-To?
_______________________
Ron Bickers
Logic Etc, Inc.
rbickers@logicetc.com
> -----Original Message-----
> From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Bobby
> Mathew
> Sent: Tuesday, April 10, 2001 2:09 AM
> To: zope@zope.org
> Subject: [Zope] Help with Search in Zope
>
>
> Hi
> I am a newbie to Zope and have been trying to get ZCatalogs to work with
> indexing my postgres data to be avaiable for search within my site. I have
> no clues on how this is possible (if possible at all?). I am able to
> follow the examples on the site to have the search working on the DTML
> documents etc. But I want to be able to search my database content. Can
> any one guide me on this please ?
> Thanks