Skip to content
Closed
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
13 changes: 13 additions & 0 deletions redisearch/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, query_string):
self._summarize_fields = []
self._highlight_fields = []
self._language = None
self._scorer = None

def query_string(self):
"""
Expand Down Expand Up @@ -198,6 +199,9 @@ def get_args(self):
if self._language:
args += ['LANGUAGE', self._language]

if self._scorer:
args += ['SCORER', self._scorer]

args += self._summarize_fields + self._highlight_fields
args += ["LIMIT", self._offset, self._num]
return args
Expand Down Expand Up @@ -279,6 +283,15 @@ def sort_by(self, field, asc=True):
self._sortby = SortbyField(field, asc)
return self

def scorer(self, scorer_type):
"""
Set a scorer to the query

- **scorer_type** - the name of the scorer
"""
self._scorer = scorer_type
return self


class Filter(object):

Expand Down
12 changes: 12 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,18 @@ def testExplain(self):
res = client.explain('@f3:f3_val @f2:f2_val @f1:f1_val')
self.assertTrue(res)

def testScorer(self):
client = self.getCleanClient('idx')
client.create_index((TextField('f1'), ))

client.add_document('doc1', f1='hello world', score=0.5)
client.add_document('doc2', f1='world hello', score=1)

q = Query('hello').scorer('TFIDF').with_scores().no_content()
self.assertEqual(client.search(q).docs[1].score, 0.5)
q = Query('hello').scorer('DISMAX').with_scores().no_content()
self.assertEqual(client.search(q).docs[1].score, 1)

def testSummarize(self):
client = self.getCleanClient('idx')
self.createIndex(client)
Expand Down