コード例 #1
0
    def test_upload_documents_existing(self, api_key, endpoint, index_name,
                                       **kwargs):
        client = SearchClient(endpoint, index_name,
                              AzureKeyCredential(api_key))
        batch_client = SearchIndexingBufferedSender(
            endpoint, index_name, AzureKeyCredential(api_key))
        batch_client._batch_size = 2
        DOCUMENTS = [
            {
                "hotelId": "1000",
                "rating": 5,
                "rooms": [],
                "hotelName": "Azure Inn"
            },
            {
                "hotelId": "3",
                "rating": 4,
                "rooms": [],
                "hotelName": "Redmond Hotel"
            },
        ]
        batch_client.upload_documents(DOCUMENTS)

        # There can be some lag before a document is searchable
        if self.is_live:
            time.sleep(TIME_TO_SLEEP)

        assert client.get_document_count() == 11
        batch_client.close()
コード例 #2
0
    def test_merge_or_upload_documents(self, api_key, endpoint, index_name,
                                       **kwargs):
        client = SearchClient(endpoint, index_name,
                              AzureKeyCredential(api_key))
        batch_client = SearchIndexingBufferedSender(
            endpoint, index_name, AzureKeyCredential(api_key))
        batch_client._batch_size = 2
        batch_client.merge_or_upload_documents([{
            "hotelId": "1000",
            "rating": 1
        }, {
            "hotelId": "4",
            "rating": 2
        }])
        batch_client.close()

        # There can be some lag before a document is searchable
        if self.is_live:
            time.sleep(TIME_TO_SLEEP)

        assert client.get_document_count() == 11

        result = client.get_document(key="1000")
        assert result["rating"] == 1

        result = client.get_document(key="4")
        assert result["rating"] == 2
 def test_search_client_index_buffered_sender(self, endpoint, api_key, index_name):
     client = SearchClient(endpoint, index_name, api_key)
     batch_client = SearchIndexingBufferedSender(endpoint, index_name, api_key)
     try:
         doc_count = 10
         doc_count = self._test_upload_documents_new(client, batch_client, doc_count)
         doc_count = self._test_upload_documents_existing(client, batch_client, doc_count)
         doc_count = self._test_delete_documents_existing(client, batch_client, doc_count)
         doc_count = self._test_delete_documents_missing(client, batch_client, doc_count)
         doc_count = self._test_merge_documents_existing(client, batch_client, doc_count)
         doc_count = self._test_merge_documents_missing(client, batch_client, doc_count)
         doc_count = self._test_merge_or_upload_documents(client, batch_client, doc_count)
     finally:
         batch_client.close()
コード例 #4
0
    def test_delete_documents_missing(self, api_key, endpoint, index_name,
                                      **kwargs):
        client = SearchClient(endpoint, index_name,
                              AzureKeyCredential(api_key))
        batch_client = SearchIndexingBufferedSender(
            endpoint, index_name, AzureKeyCredential(api_key))
        batch_client._batch_size = 2
        batch_client.delete_documents([{"hotelId": "1000"}, {"hotelId": "4"}])
        batch_client.close()

        # There can be some lag before a document is searchable
        if self.is_live:
            time.sleep(TIME_TO_SLEEP)

        assert client.get_document_count() == 9

        with pytest.raises(HttpResponseError):
            client.get_document(key="1000")

        with pytest.raises(HttpResponseError):
            client.get_document(key="4")
    def test_merge_documents_missing(self, api_key, endpoint, index_name, **kwargs):
        client = SearchClient(
            endpoint, index_name, AzureKeyCredential(api_key)
        )
        batch_client = SearchIndexingBufferedSender(
            endpoint, index_name, AzureKeyCredential(api_key)
        )
        batch_client._batch_action_count = 2
        batch_client.merge_documents(
            [{"hotelId": "1000", "rating": 1}, {"hotelId": "4", "rating": 2}]
        )
        batch_client.close()

        # There can be some lag before a document is searchable
        if self.is_live:
            time.sleep(TIME_TO_SLEEP)

        assert client.get_document_count() == 10

        with pytest.raises(HttpResponseError):
            client.get_document(key="1000")

        result = client.get_document(key="4")
        assert result["rating"] == 2