def test_OR_operator(self): q, p = parseIterQuery('foo OR bar')
def test_one_term(self): q, p = parseIterQuery("foo") self.assertEqual(q, QueryTerm(None, None, None, "foo")) o = q.optimizeMatcher(self.index) self.assertEqual(o, Term(self._fields[(None, None)], "foo"))
def test_double_quoted_term(self): q, p = parseIterQuery('"foo"')
def test_DATE_relative_date_days(self): q, p = parseIterQuery("ALL WHERE DATE FROM 1 DAY AGO") q, p = parseIterQuery("ALL WHERE DATE FROM 1 DAYS AGO")
def test_DATE_relative_date_minutes(self): q, p = parseIterQuery("ALL WHERE DATE FROM 1 MINUTE AGO") q, p = parseIterQuery("ALL WHERE DATE FROM 1 MINUTES AGO")
def test_DATE_TO_FROM_clause(self): q, p = parseIterQuery("ALL WHERE DATE TO 2000/1/1 FROM 2010/1/1")
def test_one_term(self): q = parseIterQuery("foo")
def test_double_quoted_term(self): q = parseIterQuery('"foo"')
def test_AND_operator(self): q = parseIterQuery('foo AND bar')
def test_DATE_FROM_TO_clause(self): q,p = parseIterQuery("ALL WHERE DATE FROM 2000/1/1 TO 2010/1/1")
def test_single_quoted_term(self): q = parseIterQuery("'foo'")
def test_term_function(self): q,p = parseIterQuery('message=text:is(foo)')
def test_phrase_term(self): q,p = parseIterQuery('"foo bar baz"')
def test_NOT_operator(self): q,p = parseIterQuery('NOT bar')
def test_phrase_term(self): q, p = parseIterQuery('"foo bar baz"')
def test_OR_operator(self): q = parseIterQuery('foo OR bar')
def test_DATE_FROM(self): q, p = parseIterQuery("ALL WHERE DATE FROM 2000/1/1T12:00:00")
def test_term_function(self): q = parseIterQuery('foo:text:in(hello world)')
def test_one_term(self): q,p = parseIterQuery("foo") self.assertEqual(q, QueryTerm(None, None, None, "foo")) o = q.optimizeMatcher(self.index) self.assertEqual(o, Term(self._fields[(None, None)], "foo"))
def test_DATE_FROM(self): q = parseIterQuery("WHERE DATE FROM 2000/1/1T12:00:00")
def test_DATE_relative_date_weeks(self): q, p = parseIterQuery("ALL WHERE DATE FROM 1 WEEK AGO") q, p = parseIterQuery("ALL WHERE DATE FROM 1 WEEKS AGO")
def test_DATE_TO(self): q = parseIterQuery("WHERE DATE TO 2000/1/1T12:00:00")
def test_DATE_relative_date_hours(self): q, p = parseIterQuery("ALL WHERE DATE FROM 1 HOUR AGO") q, p = parseIterQuery("ALL WHERE DATE FROM 1 HOURS AGO")
def test_DATE_TO_FROM_clause(self): q = parseIterQuery("WHERE DATE TO 2000/1/1 FROM 2010/1/1")
def test_DATE_relative_date_seconds(self): q, p = parseIterQuery("ALL WHERE DATE FROM 1 SECOND AGO") q, p = parseIterQuery("ALL WHERE DATE FROM 1 SECONDS AGO")
def test_DATE_absolute_date_and_time(self): q = parseIterQuery("WHERE DATE FROM 2000/1/1T12:00:00")
def test_single_quoted_term(self): q, p = parseIterQuery("'foo'")
def test_DATE_relative_date_weeks(self): q = parseIterQuery("WHERE DATE FROM 1 WEEK AGO") q = parseIterQuery("WHERE DATE FROM 1 WEEKS AGO")
def test_AND_operator(self): q, p = parseIterQuery('foo AND bar')
def test_DATE_relative_date_days(self): q = parseIterQuery("WHERE DATE FROM 1 DAY AGO") q = parseIterQuery("WHERE DATE FROM 1 DAYS AGO")
def test_NOT_operator(self): q, p = parseIterQuery('NOT bar')
def test_DATE_relative_date_hours(self): q = parseIterQuery("WHERE DATE FROM 1 HOUR AGO") q = parseIterQuery("WHERE DATE FROM 1 HOURS AGO")
def test_term_function(self): q, p = parseIterQuery('message=text:is(foo)')
def test_DATE_relative_date_minutes(self): q = parseIterQuery("WHERE DATE FROM 1 MINUTE AGO") q = parseIterQuery("WHERE DATE FROM 1 MINUTES AGO")
def test_DATE_TO(self): q, p = parseIterQuery("ALL WHERE DATE TO 2000/1/1T12:00:00")
def test_DATE_relative_date_seconds(self): q = parseIterQuery("WHERE DATE FROM 1 SECOND AGO") q = parseIterQuery("WHERE DATE FROM 1 SECONDS AGO")
def test_DATE_absolute_date_and_time(self): q, p = parseIterQuery("ALL WHERE DATE FROM 2000/1/1T12:00:00")
class QueryManager(Manager): implements(IManager, IQueryManager) def __init__(self, indexstore): if not IIndexStore.providedBy(indexstore): raise TypeError("indexstore class does not implement IIndexStore") Manager.__init__(self) self.setName("queries") self._indexstore = indexstore self.maxResultSize = 10 self.maxIterations = 5 self._task = getUtility(IScheduler).addTask(self.name) def configure(self, settings): pass def iterEvents(self, query, lastId=None, indices=None, limit=100, reverse=False, fields=None): """ Iterate through the database for events matching the specified query. :param query: The query string. :type query: unicode :param lastId: The ID of the last event from the previous iteration. :type lastId: str :param indices: A list of indices to search, or None to search all indices. :type indices: list, or None :param limit: The maximum number of events to return. :type limit: int :param reverse: Whether to return last results first. :type reverse: bool :param fields: A list of fields to return in the results, or None to return all fields. :type fields: list :returns: A Deferred object which receives the results. :rtype: :class:`twisted.internet.defer.Deferred` """ # look up the named indices if indices == None: indices = tuple(self._indexstore.iterSearchableIndices()) else: try: indices = tuple( self._indexstore.getSearchableIndex(name) for name in indices) except KeyError, e: raise QueryExecutionError("unknown index '%s'" % e) # if lastId is specified, make sure its a valid value if lastId != None and not isinstance(lastId, EVID): raise QueryExecutionError("lastId is not valid") # check that limit is > 0 if limit < 1: raise QueryExecutionError("limit must be greater than 0") query, period = parseIterQuery(query) logger.trace("iter query: %s" % query) logger.trace("iter period: %s" % period) # query each index and return the results def _returnIterResult(result): if isinstance(result, Failure): if result.check(SearcherError): raise QueryExecutionError(result.getErrorMessage()) result.raiseException() return QueryResult( { 'runtime': result.runtime, 'fields': result.fields }, result.events) worker = SearcherWorker(indices, query, period, lastId, reverse, fields, limit) return self._task.addWorker(worker).whenDone().addBoth( _returnIterResult)