def _poll_vq_single(self, dname, use_devmode, ddresp):
        """
        Initiate a view query for a view located in a design document
        :param ddresp: The design document to poll (as JSON)
        :return: True if successful, False if no views.
        """
        vname = None
        query = None
        v_mr = ddresp.get('views', {})
        v_spatial = ddresp.get('spatial', {})
        if v_mr:
            vname = single_dict_key(v_mr)
            query = Query()
        elif v_spatial:
            vname = single_dict_key(v_spatial)
            query = SpatialQuery()

        if not vname:
            return False

        query.stale = STALE_OK
        query.limit = 1

        for r in self._cb.query(dname,
                                vname,
                                use_devmode=use_devmode,
                                query=query):
            pass
        return True
Esempio n. 2
0
    def test_simple_spatial(self):
        spq = SpatialQuery()

        # Get all locations within five degress of the equator
        spq.start_range = [None, -5]
        spq.end_range = [None, 5]
        rows_found = [r for r in self.cb.query('geo', 'simpleGeo', query=spq)]
        self.assertEqual(2, len(rows_found))

        # Get everything on the US west
        spq.start_range = [-130, None]
        spq.end_range = [-110, None]
        rows_found = [r for r in self.cb.query('geo', 'simpleGeo', query=spq)]
        self.assertEqual(2, len(rows_found))

        # Sanity check: Ensure we actually did filtering earlier on!
        spq = SpatialQuery()
        rows_found = [r for r in self.cb.query('geo', 'simpleGeo', query=spq)]
        self.assertTrue(len(rows_found) > 2)
Esempio n. 3
0
    def test_simple_spatial(self):
        spq = SpatialQuery()

        # Get all locations within five degress of the equator
        spq.start_range = [None, -5]
        spq.end_range = [None, 5]
        rows_found = [r for r in self.cb.query('geo', 'simpleGeo', query=spq)]
        self.assertEqual(2, len(rows_found))

        # Get everything on the US west
        spq.start_range = [-130, None]
        spq.end_range  = [-110, None]
        rows_found = [r for r in self.cb.query('geo', 'simpleGeo', query=spq)]
        self.assertEqual(2, len(rows_found))

        # Sanity check: Ensure we actually did filtering earlier on!
        spq = SpatialQuery()
        rows_found = [r for r in self.cb.query('geo', 'simpleGeo', query=spq)]
        self.assertTrue(len(rows_found) > 2)
Esempio n. 4
0
def query_bounding_box(bucket, lower_left, upper_right):
    spatial_query = SpatialQuery(start_range=lower_left, end_range=upper_right)
    view = bucket.query('main', 'stops', use_devmode=True, query=spatial_query)
    return view