[Zope3-dev] KeywordIndex
Michel Pelletier
michel at dialnetwork.com
Mon Jul 18 18:31:48 EDT 2005
On Mon, 2005-07-18 at 12:00 -0400, zope3-dev-request at zope.org wrote:
> Date: Mon, 18 Jul 2005 09:14:16 -0600
> From: Jeff Shell <eucci.group at gmail.com>
> Subject: [Zope3-dev] KeywordIndex
> To: zope3-dev at zope.org
> Message-ID: <88d0d31b050718081478e06e7e at mail.gmail.com>
> 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:
<snip>
1.
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,
-Michel
More information about the Zope3-dev
mailing list