def __init__(self, start, end, startexcl, endexcl): """ :param start: The start of the time range. :type start: :class:`datetime.datetime` :param end: The end of the time range. :type end: :class:`datetime.datetime` :param startexcl: If True, then the start of the range is exclusive. :type startexcl: bool :param endexcl: If True, then the end of the range is exclusive. :type endexcl: bool """ if isinstance(start, datetime.datetime): self.start = EVID.fromDatetime(start) elif isinstance(start, EVID): self.start = start else: raise TypeError( "start must be datetime.datetime or terane.bier.evid.EVID") if isinstance(end, datetime.datetime): self.end = EVID.fromDatetime(end) elif isinstance(end, EVID): self.end = end else: raise TypeError( "end must be datetime.datetime or terane.bier.evid.EVID") self.startexcl = startexcl self.endexcl = endexcl
def __init__(self, start, end, startexcl, endexcl): """ :param start: The start of the time range. :type start: :class:`datetime.datetime` :param end: The end of the time range. :type end: :class:`datetime.datetime` :param startexcl: If True, then the start of the range is exclusive. :type startexcl: bool :param endexcl: If True, then the end of the range is exclusive. :type endexcl: bool """ if isinstance(start, datetime.datetime): self.start = EVID.fromDatetime(start) elif isinstance(start, EVID): self.start = start else: raise TypeError("start must be datetime.datetime or terane.bier.evid.EVID") if isinstance(end, datetime.datetime): self.end = EVID.fromDatetime(end) elif isinstance(end, EVID): self.end = end else: raise TypeError("end must be datetime.datetime or terane.bier.evid.EVID") self.startexcl = startexcl self.endexcl = endexcl
def test_search_Every_reverse(self): start = EVID.fromDatetime(*Bier_Searching_Tests.test_data[0][0:2]) end = EVID.fromDatetime(*Bier_Searching_Tests.test_data[-1][0:2]) period = Period(start, end, False, False) resultset = yield searchIndices([self.output.getIndex(),], Every(), period, reverse=True).whenDone() results = [EVID(*ev[0]) for ev in resultset.events] test_data = sorted([EVID.fromDatetime(ts,offset) for ts,offset,_ in Bier_Searching_Tests.test_data], reverse=True) self.assertEqual(results, test_data, "%s != %s" % ( [str(evid) for evid in results], [str(evid) for evid in test_data]))
def test_search_Every(self): start = EVID.fromDatetime(*Bier_Searching_Tests.test_data[0][0:2]) end = EVID.fromDatetime(*Bier_Searching_Tests.test_data[-1][0:2]) period = Period(start, end, False, False) resultset = yield searchIndices([ self.output.getIndex(), ], Every(), period).whenDone() results = [EVID(*ev[0]) for ev in resultset.events] test_data = [ EVID.fromDatetime(ts, offset) for ts, offset, _ in Bier_Searching_Tests.test_data ] self.assertEqual( results, test_data, "%s != %s" % ([str(evid) for evid in results], [str(evid) for evid in test_data]))
def test_read_write_index(self): contract = Contract().sign() for ts,offset,message in Output_Store_Tests.test_data: event = Event(ts, offset) event[contract.field_message] = message self.output.receiveEvent(event) # read back from the index index = self.output.getIndex() startId = EVID.fromDatetime(*Output_Store_Tests.test_data[0][0:2]) endId = EVID.fromDatetime(*Output_Store_Tests.test_data[-1][0:2]) searcher = index.newSearcher() try: npostings = searcher.postingsLength(None, None, startId, endId) self.assertTrue(npostings == len(Output_Store_Tests.test_data)) i = searcher.iterPostings(None, None, startId, endId) postings = [] while True: posting = i.nextPosting() if posting == (None, None, None): break postings.append(posting) finally: searcher.close()
: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 0, return the id of the latest document if lastId == None: return QueryResult({'runtime': 0.0, 'lastId': str(EVID.fromDatetime())}, []) try: lastId = EVID.fromString(lastId) except: raise QueryExecutionError("invalid lastId '%s'" % str(lastId)) # check that limit is > 0 if limit < 1: raise QueryExecutionError("limit must be greater than 0") query = parseTailQuery(query) logger.trace("tail query: %s" % query) period = Period(lastId, EVID.fromString(EVID.MAX_ID), True, False) logger.trace("tail period: %s" % period) # query each index, and return the results task = searchIndices(indices, query, period, None, False, fields, limit) def _returnTailResult(result, lastId=None): if isinstance(result, Failure) and result.check(SearcherError):
# 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 0, return the id of the latest document if lastId == None: return QueryResult( { 'runtime': 0.0, 'lastId': str(EVID.fromDatetime()) }, []) try: lastId = EVID.fromString(lastId) except: raise QueryExecutionError("invalid lastId '%s'" % str(lastId)) # check that limit is > 0 if limit < 1: raise QueryExecutionError("limit must be greater than 0") query = parseTailQuery(query) logger.trace("tail query: %s" % query) period = Period(lastId, EVID.fromString(EVID.MAX_ID), True, False) logger.trace("tail period: %s" % period) # query each index, and return the results def _returnTailResult(result, lastId=None):