Skip to content
This repository was archived by the owner on Sep 1, 2021. It is now read-only.

Commit 9811afa

Browse files
committed
Added support for updating documents
1 parent 4e4f214 commit 9811afa

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ The client can be configured to use a managed deploy by adjusting the `base_endp
9494
[{'id': 'INscMGmhmX4', 'errors': []}, {'id': 'JNDFojsd02', 'errors': []}]
9595
```
9696

97+
### Indexing: Updating documents (Partial Updates)
98+
99+
```python
100+
>>> engine_name = 'favorite-videos'
101+
>>> documents = [
102+
{
103+
'id': 'INscMGmhmX4',
104+
'title': 'Updated title'
105+
}
106+
]
107+
108+
>>> client.update_documents(engine_name, documents)
109+
```
110+
97111
### Get Documents
98112

99113
```python
@@ -119,7 +133,6 @@ The client can be configured to use a managed deploy by adjusting the `base_endp
119133
}
120134
```
121135

122-
123136
### Destroy Documents
124137

125138
```python

swiftype_app_search/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ def index_documents(self, engine_name, documents):
8181

8282
return self.swiftype_session.request('post', endpoint, data=data)
8383

84+
def update_documents(self, engine_name, documents):
85+
"""
86+
Update a batch of documents for an engine.
87+
88+
:param engine_name: Name of engine to index documents into.
89+
:param documents: Hashes representing documents.
90+
:return: Array of document status dictionaries. Errors will be present
91+
in a document status with a key of `errors`.
92+
"""
93+
endpoint = "engines/{}/documents".format(engine_name)
94+
data = json.dumps(documents)
95+
96+
return self.swiftype_session.request('patch', endpoint, data=data)
97+
8498
def destroy_documents(self, engine_name, document_ids):
8599
"""
86100
Destroys documents by id for an engine.

tests/test_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ def test_index_documents(self):
7171
response = self.client.index_documents(self.engine_name, [valid_document, other_document])
7272
self.assertEqual(response, expected_return)
7373

74+
def test_update_documents(self):
75+
id = 'INscMGmhmX4'
76+
valid_document = {'id': id}
77+
other_document = { 'body': 'some value' }
78+
79+
expected_return = [
80+
{'id': id, 'errors': []},
81+
{'id': 'some autogenerated id', 'errors': []}
82+
]
83+
84+
with requests_mock.Mocker() as m:
85+
m.register_uri('PATCH', self.document_index_url, json=expected_return, status_code=200)
86+
response = self.client.update_documents(self.engine_name, [valid_document, other_document])
87+
self.assertEqual(response, expected_return)
88+
7489
def test_get_documents(self):
7590
id = 'INscMGmhmX4'
7691
expected_return = [

0 commit comments

Comments
 (0)