=== modified file 'fts/fts.py' --- fts/fts.py 2010-08-05 14:37:07 +0000 +++ fts/fts.py 2010-08-06 21:53:14 +0000 @@ -41,7 +41,7 @@ import threading import gobject, gio -from zeitgeist.datamodel import Symbol, StorageState, ResultType, TimeRange, NULL_EVENT +from zeitgeist.datamodel import Symbol, StorageState, ResultType, TimeRange, NULL_EVENT, NEGATION_OPERATOR from _zeitgeist.engine.datamodel import Event, Subject from _zeitgeist.engine.extension import Extension from _zeitgeist.engine import constants @@ -122,6 +122,7 @@ QUERY_PARSER_FLAGS = xapian.QueryParser.FLAG_PHRASE | \ xapian.QueryParser.FLAG_BOOLEAN | \ + xapian.QueryParser.FLAG_PURE_NOT | \ xapian.QueryParser.FLAG_LOVEHATE | \ xapian.QueryParser.FLAG_WILDCARD @@ -460,6 +461,16 @@ except Exception, e: log.error("Error indexing event: %s" % e) + def _expand_type (self, type_prefix, uri): + is_negation = uri.startswith(NEGATION_OPERATOR) + uri = uri[1:] if is_negation else uri + children = Symbol.find_child_uris_extended(uri) + children = [ "%s:%s" % (type_prefix, child) for child in children ] + + result = " OR ".join(children) + + return result if not is_negation else "NOT (%s)" % result + def _compile_event_filter_query (self, events): """Takes a list of event templates and compiles a filter query based on their, interpretations, manifestations, and actor, @@ -477,23 +488,15 @@ tmpl = [] if event.interpretation : - children = Symbol.find_child_uris_extended(event.interpretation) - children = [ "zgei:%s" % child for child in children ] - tmpl.append(" OR ".join(children)) + tmpl.append(self._expand_type("zgei", event.interpretation)) if event.manifestation : - children = Symbol.find_child_uris_extended(event.manifestation) - children = [ "zgem:%s" % child for child in children ] - tmpl.append(" OR ".join(children)) + tmpl.append(self._expand_type("zgem", event.manifestation)) if event.actor : tmpl.append("zga:"+event.actor) for su in event.subjects: if su.interpretation : - children = Symbol.find_child_uris_extended(su.interpretation) - children = [ "zgsi:%s" % child for child in children ] - tmpl.append(" OR ".join(children)) + tmpl.append(self._expand_type("zgsi", su.interpretation)) if su.manifestation : - children = Symbol.find_child_uris_extended(su.manifestation) - children = [ "zgsm:%s" % child for child in children ] - tmpl.append(" OR ".join(children)) + tmpl.append(self._expand_type("zgsm", su.manifestation)) tmpl = "(" + ") AND (".join(tmpl) + ")" query.append(tmpl)