~ubuntu-branches/ubuntu/trusty/zeitgeist-extensions/trusty

« back to all changes in this revision

Viewing changes to fts/fts.py

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-08-13 12:52:08 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100813125208-y7625ddp64h9r2z3
Tags: 0.0.4-0ubuntu1
* New upstream release.
* debian/control:
  - Architecture: all

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
import threading
42
42
import gobject, gio
43
43
 
44
 
from zeitgeist.datamodel import Symbol, StorageState, ResultType, TimeRange, NULL_EVENT
 
44
from zeitgeist.datamodel import Symbol, StorageState, ResultType, TimeRange, NULL_EVENT, NEGATION_OPERATOR
45
45
from _zeitgeist.engine.datamodel import Event, Subject
46
46
from _zeitgeist.engine.extension import Extension
47
47
from _zeitgeist.engine import constants
122
122
        
123
123
        QUERY_PARSER_FLAGS = xapian.QueryParser.FLAG_PHRASE |   \
124
124
                             xapian.QueryParser.FLAG_BOOLEAN |  \
 
125
                             xapian.QueryParser.FLAG_PURE_NOT |  \
125
126
                             xapian.QueryParser.FLAG_LOVEHATE | \
126
127
                             xapian.QueryParser.FLAG_WILDCARD
127
128
        
460
461
                except Exception, e:
461
462
                        log.error("Error indexing event: %s" % e)
462
463
 
 
464
        def _expand_type (self, type_prefix, uri):
 
465
                is_negation = uri.startswith(NEGATION_OPERATOR)
 
466
                uri = uri[1:] if is_negation else uri
 
467
                children = Symbol.find_child_uris_extended(uri)
 
468
                children = [ "%s:%s" % (type_prefix, child) for child in children ]
 
469
 
 
470
                result = " OR ".join(children)
 
471
 
 
472
                return result if not is_negation else "NOT (%s)" % result
 
473
 
463
474
        def _compile_event_filter_query (self, events):
464
475
                """Takes a list of event templates and compiles a filter query
465
476
                   based on their, interpretations, manifestations, and actor,
477
488
                        
478
489
                        tmpl = []
479
490
                        if event.interpretation :
480
 
                                children = Symbol.find_child_uris_extended(event.interpretation)
481
 
                                children = [ "zgei:%s" % child for child in children ]
482
 
                                tmpl.append(" OR ".join(children))
 
491
                                tmpl.append(self._expand_type("zgei", event.interpretation))
483
492
                        if event.manifestation :
484
 
                                children = Symbol.find_child_uris_extended(event.manifestation)
485
 
                                children = [ "zgem:%s" % child for child in children ]
486
 
                                tmpl.append(" OR ".join(children))
 
493
                                tmpl.append(self._expand_type("zgem", event.manifestation))
487
494
                        if event.actor : tmpl.append("zga:"+event.actor)
488
495
                        for su in event.subjects:
489
496
                                if su.interpretation :
490
 
                                        children = Symbol.find_child_uris_extended(su.interpretation)
491
 
                                        children = [ "zgsi:%s" % child for child in children ]
492
 
                                        tmpl.append(" OR ".join(children))
 
497
                                        tmpl.append(self._expand_type("zgsi", su.interpretation))
493
498
                                if su.manifestation :
494
 
                                        children = Symbol.find_child_uris_extended(su.manifestation)
495
 
                                        children = [ "zgsm:%s" % child for child in children ]
496
 
                                        tmpl.append(" OR ".join(children))
 
499
                                        tmpl.append(self._expand_type("zgsm", su.manifestation))
497
500
                        
498
501
                        tmpl = "(" + ") AND (".join(tmpl) + ")"
499
502
                        query.append(tmpl)