Skip to content

Commit e8cc5a7

Browse files
authored
fix: ensure limit works in elastic (#279)
1 parent d12710c commit e8cc5a7

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

docarray/array/mixins/find.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def find(
135135
elif isinstance(query, str) or (
136136
isinstance(query, list) and isinstance(query[0], str)
137137
):
138-
result = self._find_by_text(query, index=index, **kwargs)
138+
result = self._find_by_text(query, index=index, limit=limit, **kwargs)
139139

140140
if len(result) == 1:
141141
return result[0]

tests/unit/array/mixins/test_find.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def test_find_by_text(storage, config, start_storage):
9494
assert isinstance(results, DocumentArray)
9595
assert len(results) == 2
9696
assert set(results[:, 'id']) == {'1', '3'}
97+
results = da.find('token3 token4', limit=1)
98+
assert len(results) == 1
9799

98100
results = da.find(['token4', 'token'])
99101
assert isinstance(results, list)
@@ -109,7 +111,7 @@ def test_find_by_text(storage, config, start_storage):
109111
('elasticsearch', {'n_dim': 32, 'tag_indices': ['attr1', 'attr2', 'attr3']}),
110112
],
111113
)
112-
def test_find_by_tag(storage, config):
114+
def test_find_by_tag(storage, config, start_storage):
113115
da = DocumentArray(storage=storage, config=config)
114116
da.extend(
115117
[
@@ -146,6 +148,9 @@ def test_find_by_tag(storage, config):
146148
assert results[0].id == '1'
147149
assert results[1].id == '2'
148150

151+
results = da.find('token1 token2', index='attr1', limit=1)
152+
assert len(results) == 1
153+
149154
results = da.find('token2 token4', index='attr1')
150155
assert len(results) == 2
151156
assert set(results[:, 'id']) == {'1', '3'}
@@ -159,6 +164,9 @@ def test_find_by_tag(storage, config):
159164
assert results[0].id == '2'
160165
assert results[1].id == '1'
161166

167+
results = da.find('token6', index='attr3', limit=1)
168+
assert len(results) == 1
169+
162170
results = da.find('token5', index='attr3')
163171
assert len(results) == 2
164172
assert set(results[:, 'id']) == {'1', '3'}

0 commit comments

Comments
 (0)