Skip to content

Commit 0a225fc

Browse files
authored
Revert Search 2.0 changes (#75)
* Revert Search 2.0 changes * catch error on addhash
1 parent 037b953 commit 0a225fc

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
docker:
1010
- image: circleci/python:2.7.15
11-
- image: redislabs/redisearch:edge
11+
- image: redislabs/redisearch:latest
1212

1313
working_directory: ~/repo
1414

redisearch/client.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class Client(object):
109109
ALTER_CMD = 'FT.ALTER'
110110
SEARCH_CMD = 'FT.SEARCH'
111111
ADD_CMD = 'FT.ADD'
112+
ADDHASH_CMD = "FT.ADDHASH"
112113
DROP_CMD = 'FT.DROP'
113114
EXPLAIN_CMD = 'FT.EXPLAIN'
114115
DEL_CMD = 'FT.DEL'
@@ -209,7 +210,7 @@ def create_index(self, fields, no_term_offsets=False,
209210
- **stopwords**: If not None, we create the index with this custom stopword list. The list can be empty
210211
"""
211212

212-
args = [self.CREATE_CMD, self.index_name, 'ON', 'HASH']
213+
args = [self.CREATE_CMD, self.index_name]
213214
if no_term_offsets:
214215
args.append(self.NOOFFSETS)
215216
if no_field_flags:
@@ -275,6 +276,25 @@ def _add_document(self, doc_id, conn=None, nosave=False, score=1.0, payload=None
275276
args += list(itertools.chain(*fields.items()))
276277
return conn.execute_command(*args)
277278

279+
def _add_document_hash(
280+
self, doc_id, conn=None, score=1.0, language=None, replace=False,
281+
):
282+
"""
283+
Internal add_document_hash used for both batch and single doc indexing
284+
"""
285+
if conn is None:
286+
conn = self.redis
287+
288+
args = [self.ADDHASH_CMD, self.index_name, doc_id, score]
289+
290+
if replace:
291+
args.append("REPLACE")
292+
293+
if language:
294+
args += ["LANGUAGE", language]
295+
296+
return conn.execute_command(*args)
297+
278298
def add_document(self, doc_id, nosave=False, score=1.0, payload=None,
279299
replace=False, partial=False, language=None, no_create=False, **fields):
280300
"""

test/test.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,40 @@ def getCleanClient(self, name):
172172

173173
return client
174174

175+
def testAddHash(self):
176+
conn = self.redis()
177+
178+
with conn as r:
179+
# Creating a client with a given index name
180+
client = Client('idx', port=conn.port)
181+
182+
client.redis.flushdb()
183+
# Creating the index definition and schema
184+
client.create_index((TextField('title',
185+
weight=5.0), TextField('body')))
186+
187+
client.redis.hset(
188+
'doc1',
189+
mapping={
190+
'title': 'RediSearch',
191+
'body': 'Redisearch impements a search engine on top of redis'
192+
})
193+
194+
try:
195+
# Indexing the hash
196+
client.add_document_hash('doc1')
197+
except redis.ResponseError as e:
198+
# Support for FT.ADDHASH was removed in RediSearch 2.0
199+
self.assertTrue( str(e).startswith('unknown command `FT.ADDHASH`'))
200+
return
201+
202+
# Searching with complext parameters:
203+
q = Query("search engine").verbatim().no_content().paging(0, 5)
204+
205+
res = client.search(q)
206+
207+
self.assertEqual('doc1', res.docs[0].id)
208+
175209
def testPayloads(self):
176210

177211
conn = self.redis()

0 commit comments

Comments
 (0)