[Zope-dev] ZCatalog/TextIndex/OR - keyword search

Steve Alexander steve@cat-box.net
Thu, 08 Feb 2001 11:08:49 +0000


Arno Gross wrote:

> I understand that the search terms for a field with TextIndex are ORed
> and the fields in a search form are ANDed.
> But assume the following:
>  * I have three fields (eg. abstract, content, title) with TextIndex
>  * I have one field (eg. category) with FieldIndex
> 
> When searching I want just give a keyword for the three TextIndex fields
> and a search term for category.
> The applying expression should look like this:
> 
> (abstract=keyword OR content=keyword OR title=keyword) AND
> category=searchTerm
> 
> Any hints?

Create a method or computed attribute called "search_text" that returns the
concatenation of abstract, content and title.

In ZPatterns I'd use the following SkinScript:

  WITH SELF COMPUTE
    search_text='%s %s %s' % (abstract, content, title)

An equivalent PythonScript as a method of your ZClass would be:

name: search_text
  return '%s %s %s' % (container.abstract, container.content, container.title)

Use a similar method in a python class, replacing "container" with "self".

Set up search_text as a TextIndex in your ZCatalog.

Then, query the catalog with something like:

  Catalog(search_text=keyword_for_query, category=searchTerm)

The standard name for the search_text method or attribute is
PrincipiaSearchSource. That's why PrincipiaSearchSource is a default
TextIndex in a new ZCatalog.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net