def test_range_query(self):
        q = Query()

        q.mapkey_range = [["abbaye_de_maredsous"], ["abbaye_de_maredsous", Query.STRING_RANGE_END]]

        q.inclusive_end = True

        ret = self.cb.query("beer", "brewery_beers", query=q)
        rows = list(ret)
        self.assertEqual(len(rows), 4)

        q.mapkey_range = [["u"], ["v"]]
        ret = self.cb.query("beer", "brewery_beers", query=q)
        self.assertEqual(len(list(ret)), 88)

        q.mapkey_range = [["u"], ["uppper" + Query.STRING_RANGE_END]]
        ret = self.cb.query("beer", "brewery_beers", query=q)
        rows = list(ret)
        self.assertEqual(len(rows), 56)
Beispiel #2
0
    def test_range_query(self):
        q = Query()

        q.mapkey_range = [["abbaye_de_maredsous"],
                          ["abbaye_de_maredsous", Query.STRING_RANGE_END]]

        q.inclusive_end = True

        ret = self.cb.query("beer", "brewery_beers", query=q)
        rows = list(ret)
        self.assertEqual(len(rows), 4)

        q.mapkey_range = [["u"], ["v"]]
        ret = self.cb.query("beer", "brewery_beers", query=q)
        self.assertEqual(len(list(ret)), 88)

        q.mapkey_range = [["u"], ["uppper" + Query.STRING_RANGE_END]]
        ret = self.cb.query("beer", "brewery_beers", query=q)
        rows = list(ret)
        self.assertEqual(len(rows), 56)
    def search(self, start_ts, end_ts):
        #print '--> search: ', start_it, end_ts
        """Searches in Couchbase and finds all documents that were
        modified or deleted within the timestamp range.
        """
        q = Query(inclusive_end=False)
        q.mapkey_range = [start_ts, end_ts + q.STRING_RANGE_END]
        view = View(self.couchbase, "mongo_connect", "by_timestamp", query=q, include_docs=True)

        for row in view:
            print row
            yield result.doc.value
Beispiel #4
0
 def getByView(self, parameter):
     bucket = Bucket(self._bucketUrl)
     options = Query()
     options.mapkey_range = (str(parameter), str(parameter))
     options.stale = False
     rows = bucket.query(self.designDocument, self._viewName, query=options)
     # the resulting row view from bucket.query is [key, value, docid, doc]
     # since we want docids, select the elements with index 2
     docids = [row[2] for row in rows]
     if len(docids) == 0:
         return []
     results = bucket.get_multi(docids).values()
     return [result.value for result in results]
Beispiel #5
0
    def search(self, start_ts, end_ts):
        #print '--> search: ', start_it, end_ts
        """Searches in Couchbase and finds all documents that were
        modified or deleted within the timestamp range.
        """
        q = Query(inclusive_end=False)
        q.mapkey_range = [start_ts, end_ts + q.STRING_RANGE_END]
        view = View(self.couchbase,
                    "mongo_connect",
                    "by_timestamp",
                    query=q,
                    include_docs=True)

        for row in view:
            print row
            yield result.doc.value
Beispiel #6
0
def brewery_search():
    value = request.args.get('value')
    q = Query()
    q.mapkey_range = [value, value + Query.STRING_RANGE_END]
    q.limit = ENTRIES_PER_PAGE

    ret = []

    rp = BreweryRowProcessor()
    res = db.query("brewery", "by_name",
                   row_processor=rp, query=q, include_docs=True)
    for brewery in res:
        ret.append({'id' : brewery.id,
                    'name' : brewery.name})

    return return_search_json(ret)
Beispiel #7
0
def beer_search():
    value = request.args.get('value')
    q = Query()
    q.mapkey_range = [value, value + Query.STRING_RANGE_END]
    q.limit = ENTRIES_PER_PAGE

    ret = []

    res = db.query("beer", "by_name", row_processor=BeerRowProcessor(),
                   query=q, include_docs=True)

    for beer in res:
        ret.append({'id' : beer.id,
                    'name' : beer.name,
                    'brewery' : beer.brewery_id})

    return return_search_json(ret)
Beispiel #8
0
def customer_search():
    value = request.args.get('value')
    q = Query()
    q.mapkey_range = [value, value + Query.STRING_RANGE_END]
    q.limit = ENTRIES_PER_PAGE

    ret = []

    rp = RowProcessor(rowclass=CustomerRow)
    res = db.query("customer", "by_name",
                   row_processor=rp,
                   query=q,
                   include_docs=True)
    for customer in res:
        print customer
        ret.append({'id' : customer.id,
                    'name' : customer.name})

    return return_search_json(ret)
Beispiel #9
0
def log_search():
    value = request.args.get('value')
    q = Query()
    q.mapkey_range = [value, value + Query.STRING_RANGE_END]
    q.limit = ENTRIES_PER_PAGE

    ret = []

    rp = Node_SnapshotListRowProcessor()
    res = db.query("node_snapshot", "by_name",
                   row_processor=rp,
                   query=q,
                   include_docs=True)

    for log in res:
        ret.append({'id' : log.id,
                    'name' : log.name,
                    'customer' : log.customer_id})

    return return_search_json(ret)