Skip to content

Revert Search 2.0 changes #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
docker:
- image: circleci/python:2.7.15
- image: redislabs/redisearch:edge
- image: redislabs/redisearch:latest

working_directory: ~/repo

Expand Down
22 changes: 21 additions & 1 deletion redisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Client(object):
ALTER_CMD = 'FT.ALTER'
SEARCH_CMD = 'FT.SEARCH'
ADD_CMD = 'FT.ADD'
ADDHASH_CMD = "FT.ADDHASH"
DROP_CMD = 'FT.DROP'
EXPLAIN_CMD = 'FT.EXPLAIN'
DEL_CMD = 'FT.DEL'
Expand Down Expand Up @@ -209,7 +210,7 @@ def create_index(self, fields, no_term_offsets=False,
- **stopwords**: If not None, we create the index with this custom stopword list. The list can be empty
"""

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

def _add_document_hash(
self, doc_id, conn=None, score=1.0, language=None, replace=False,
):
"""
Internal add_document_hash used for both batch and single doc indexing
"""
if conn is None:
conn = self.redis

args = [self.ADDHASH_CMD, self.index_name, doc_id, score]

if replace:
args.append("REPLACE")

if language:
args += ["LANGUAGE", language]

return conn.execute_command(*args)

def add_document(self, doc_id, nosave=False, score=1.0, payload=None,
replace=False, partial=False, language=None, no_create=False, **fields):
"""
Expand Down
34 changes: 34 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,40 @@ def getCleanClient(self, name):

return client

def testAddHash(self):
conn = self.redis()

with conn as r:
# Creating a client with a given index name
client = Client('idx', port=conn.port)

client.redis.flushdb()
# Creating the index definition and schema
client.create_index((TextField('title',
weight=5.0), TextField('body')))

client.redis.hset(
'doc1',
mapping={
'title': 'RediSearch',
'body': 'Redisearch impements a search engine on top of redis'
})

try:
# Indexing the hash
client.add_document_hash('doc1')
except redis.ResponseError as e:
# Support for FT.ADDHASH was removed in RediSearch 2.0
self.assertTrue( str(e).startswith('unknown command `FT.ADDHASH`'))
return

# Searching with complext parameters:
q = Query("search engine").verbatim().no_content().paging(0, 5)

res = client.search(q)

self.assertEqual('doc1', res.docs[0].id)

def testPayloads(self):

conn = self.redis()
Expand Down