On Mon, 2005-07-18 at 12:00 -0400, [EMAIL PROTECTED] wrote:

> Date: Mon, 18 Jul 2005 09:14:16 -0600
> From: Jeff Shell <[EMAIL PROTECTED]>
> Subject: [Zope3-dev] KeywordIndex
> To: zope3-dev@zope.org
> Content-Type: text/plain; charset=ISO-8859-1
> I'm working on a simple application which is the first time I get to
> use the catalog in Zope 3. I'm writing against Zope 3.1b1. I was
> dismayed not to see KeywordIndex in the main catalog set, but then I
> found it in zope.index.keyword. But it seems to be a bit behind. I
> have it somewhat working through subclassing, etc, but it's been
> purely guess work on my part to get things this far. In my product
> package, I have the following:

I'm unable to help you directly with your problem, although Gary's post
about the SetIndex looks very promising and I would like to see that
code as well.  As you said, something like a keyword index is exactly
what your application is designed around, but if I could digress from
the topic a little I'd like to suggest another solution, rdflib.

rdflib covers some of the same use cases as a keyword index.  Your
objects (content, whatever) and your keywords would be assigned unique
identifiers.  You then add relations to an rdflib.Graph that associate
the keyword with your objects:

>>> dc = rdflib.Namespace('http://purl.org/dc/elements/1.1/')
>>> blue = rdflib.BNode()  # creates a URI for you
>>> g = rdflib.Graph()
>>> g.add((object_uri, dc.keywords, blue))

and then query the data back out with either a low-level g.triples((s,
p, o)) pattern or a sparql query.  For example, print a list of all
object URIs that have the blue_uri keyword:

>>> print [s for (s, p, o) in g.triples((rdflib.Any, dc.keywords, blue))]

or sparql:

>>> sg = rdflib.sparqlGraph(g)
>>> select = ("?object_uri",)
>>> where = rdflib.GraphPattern([("?object_uri", dc.keywords, blue)])
>>> for object_uri in sg.query(select, where): print object_uri

is the same query, but longer.  With sparql you can do more complex sql
like queries however against other relations.  

Hope this helps,


Zope3-dev mailing list
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to