예제 #1
0
    def replace_all_objects(self, objects, request_options=None):
        # type: (Union[List[dict], Iterator[dict]], Optional[Union[dict, RequestOptions]]) -> MultipleResponse # noqa: E501

        safe = False
        if isinstance(request_options, dict) and "safe" in request_options:
            safe = request_options.pop("safe")

        tmp_index_name = self._create_temporary_name()
        responses = MultipleResponse()
        responses.push(
            self.copy_to(tmp_index_name, {"scope": ["settings", "synonyms", "rules"]})
        )

        if safe:
            responses.wait()

        try:
            from algoliasearch.search_client import SearchClient
        except ImportError:  # Already imported.
            pass

        tmp_client = SearchClient(self._transporter, self._config)
        tmp_index = tmp_client.init_index(tmp_index_name)

        responses.push(tmp_index.save_objects(objects, request_options))

        if safe:
            responses.wait()

        responses.push(tmp_index.move_to(self._name))

        if safe:
            responses.wait()

        return responses
    def setUp(self):
        self.config = SearchConfig('foo', 'bar')
        self.transporter = Transporter(Requester(), self.config)
        self.transporter.read = mock.Mock(name="read")
        self.transporter.read.return_value = {}
        self.transporter.write = mock.Mock(name="write")
        self.transporter.write.return_value = {}

        self.client = SearchClient(self.transporter, self.config)
    def __init__(self, search_client, transporter, search_config):
        # type: (SearchClient, TransporterAsync, SearchConfig) -> None

        self._search_client = search_client
        self._transporter_async = transporter

        super(SearchClientAsync, self).__init__(search_client._transporter,
                                                search_config)

        search_client = SearchClient(transporter, search_config)
        search_client.__setattr__('init_index', self.init_index)
        search_client.__setattr__('_sync', self._sync)
        _create_async_methods_in(self, search_client)
예제 #4
0
    def replace_all_objects_async(  # type: ignore
            self,
            objects,
            request_options=None,
    ):
        # type: (Union[List[dict], Iterator[dict]], Optional[Union[dict, RequestOptions]]) -> MultipleResponse # noqa: E501

        safe = False
        if isinstance(request_options, dict) and "safe" in request_options:
            safe = request_options.pop("safe")

        tmp_index_name = self._create_temporary_name()
        responses = MultipleResponse()
        response = yield from self.copy_to_async(  # type: ignore
            tmp_index_name, {"scope": ["settings", "synonyms", "rules"]})
        responses.push(response)

        if safe:
            responses.wait()

        tmp_client = SearchClient(self._transporter, self._config)
        tmp_index = SearchIndexAsync(
            tmp_client.init_index(tmp_index_name),
            self._transporter_async,
            self._config,
            tmp_index_name,
        )

        response = yield from tmp_index.save_objects_async(  # type: ignore
            objects, request_options)
        responses.push(response)

        if safe:
            responses.wait()

        response = yield from tmp_index.move_to_async(  # type: ignore
            self._name)
        responses.push(response)

        if safe:
            responses.wait()

        return responses