コード例 #1
0
    def test_near_position(self):
        """
        """

        # 50.850278, 4.348611 => Brussels

        near_docs = SimpleIndexQuery.near(
            collection=self.test_1_col,
            latitude=50.850278,
            longitude=4.348611,
            index_id=self.geo_index.index_type_obj.id,
            limit=2)

        self.assertEqual(len(near_docs), 2)

        koeln_doc = near_docs[0]
        paris_doc = near_docs[1]

        self.assertDocumentsEqual(koeln_doc, self.col1_doc2)
        self.assertDocumentsEqual(paris_doc, self.col1_doc1)
コード例 #2
0
ファイル: tests.py プロジェクト: garym/ArangoPy
    def test_near_position(self):
        """
        """

        # 50.850278, 4.348611 => Brussels

        near_docs = SimpleIndexQuery.near(
            collection=self.test_1_col,
            latitude=50.850278,
            longitude=4.348611,
            index_id=self.geo_index.index_type_obj.id,
            limit=2
        )

        self.assertEqual(len(near_docs), 2)

        koeln_doc = near_docs[0]
        paris_doc = near_docs[1]

        self.assertDocumentsEqual(koeln_doc, self.col1_doc2)
        self.assertDocumentsEqual(paris_doc, self.col1_doc1)
コード例 #3
0
    def _generate_cache(self):
        """
        """

        super(IndexQueryset, self)._generate_cache()

        index_field = getattr(self._manager._model_class, self._index)
        result = None

        # All have these attributes
        if 'skip' in self._filters:
            skip = self._filters['skip']
        else:
            skip = None

        if 'limit' in self._filters:
            limit = self._filters['limit']
        else:
            limit = None

        # Hash index
        if index_field.index_type_obj.type_name == 'hash':

            result = SimpleIndexQuery.get_by_example_hash(
                collection=index_field.collection,
                index_id=index_field.index_type_obj.id,
                example_data=self._filters,
                allow_multiple=True,
                skip=skip,
                limit=limit,
            )

        # Skiplist index
        if index_field.index_type_obj.type_name == 'skiplist':

            range_query = 'left' in self._filters
            range_query = range_query and 'right' in self._filters
            range_query = range_query and 'closed' in self._filters
            range_query = range_query and 'attribute' in self._filters

            # Range query
            if range_query:
                result = SimpleIndexQuery.range(
                    collection=index_field.collection,
                    index_id=index_field.index_type_obj.id,
                    attribute=self._filters['attribute'],
                    left=self._filters['left'],
                    right=self._filters['right'],
                    closed=self._filters['closed'],
                    skip=skip,
                    limit=limit,
                )

            # Normal search query
            else:
                result = SimpleIndexQuery.get_by_example_skiplist(
                    collection=index_field.collection,
                    index_id=index_field.index_type_obj.id,
                    example_data=self._filters,
                    allow_multiple=True,
                    skip=skip,
                    limit=limit,
                )

        # Fulltext index
        if index_field.index_type_obj.type_name == 'fulltext':

            result = SimpleIndexQuery.fulltext(
                collection=index_field.collection,
                index_id=index_field.index_type_obj.id,
                attribute=self._filters['attribute'],
                example_text=self._filters['example_text'],
                skip=skip,
                limit=limit,
            )

        # Cap constraint
        if index_field.index_type_obj.type_name == 'cap':
            pass

        # Geo index
        if index_field.index_type_obj.type_name == 'geo':

            if 'radius' in self._filters:
                result = SimpleIndexQuery.within(
                    collection=index_field.collection,
                    index_id=index_field.index_type_obj.id,
                    latitude=self._filters['latitude'],
                    longitude=self._filters['longitude'],
                    radius=self._filters['radius'],
                    distance=self._filters['distance'],
                    skip=skip,
                    limit=limit,
                )
            else:
                result = SimpleIndexQuery.near(
                    collection=index_field.collection,
                    index_id=index_field.index_type_obj.id,
                    latitude=self._filters['latitude'],
                    longitude=self._filters['longitude'],
                    distance=self._filters['distance'],
                    skip=skip,
                    limit=limit,
                )

        # Save cache
        if isinstance(result, list):
            self._cache = result
        else:
            self._cache.append(result)