示例#1
0
    def test_search(self):
        instance = self._create_test_data()
        search.index_entity(instance, index="test_index")

        error, results, current_cursor, next_cursor = search.search("test_index", "")

        assert not error
        assert len(results) == 1
示例#2
0
    def test_search(self):
        instance = self._create_test_data()
        search.index_entity(instance, index='test_index')

        error, results, current_cursor, next_cursor = search.search('test_index', '')

        assert not error
        assert len(results) == 1
示例#3
0
    def search(self, index=None, query=None, limit=None, cursor=None, sort_field=None, sort_direction='asc', sort_default_value=None, options=None):
        """
        Searches using the provided index (or an automatically determine one).

        Expects the search query to be in the ``query`` request parameter.

        Also takes care of setting pagination information if the :class:`pagination component <ferris.components.pagination.Pagnation>` is present.
        """

        index = index if index else self._get_index()
        query_string = query if query else self.controller.request.params.get('query', '')
        options = options if options else {}

        if 'pagination' in self.controller.components:
            cursor, limit = self.controller.components.pagination.get_pagination_params(cursor, limit)

        error, results, cursor, next_cursor = ferris_search.search(
            index,
            query_string,
            cursor=cursor,
            limit=limit,
            options=options,
            sort_field=sort_field,
            sort_direction=sort_direction,
            sort_default_value=sort_default_value)

        if error:
            self.controller.context['search_error'] = error

        if 'pagination' in self.controller.components:
            self.controller.components.pagination.set_pagination_info(
                current_cursor=cursor,
                next_cursor=next_cursor,
                limit=limit,
                count=len(results))

        self.controller.context['search_query'] = query_string
        self.controller.context['search_results'] = results

        if hasattr(self.controller, 'scaffold'):
            self.controller.context[self.controller.scaffold.plural] = results

        return results