Skip to content

Commit

Permalink
Insert to heap only if score larger than minimum (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtul committed Jan 4, 2021
1 parent 7cfe4ea commit ac0973d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/trie/trie_type.c
Expand Up @@ -194,7 +194,7 @@ Vector *Trie_Search(Trie *tree, const char *s, size_t len, size_t num, int maxDi
}

} else {
if (ent->score >= it->minScore) {
if (ent->score > it->minScore) {
pooledEntry = heap_poll(pq);
rm_free(pooledEntry->str);
pooledEntry->str = NULL;
Expand Down
12 changes: 11 additions & 1 deletion tests/pytests/test_suggest.py
Expand Up @@ -91,7 +91,7 @@ def testIssue_866(env):
env.expect('ft.sugdel', 'sug', 'test').equal(0)
env.expect('ft.sugget', 'sug', '').equal(['test123', 'test456'])

def testSuggetMax(env):
def testSuggestMax(env):
for i in range(10):
env.expect('ft.sugadd', 'sug', 'test%d' % i, i + 1).equal(i + 1)
# for j in range(i + 1):
Expand All @@ -104,3 +104,13 @@ def testSuggetMax(env):
for i in range(1,11):
env.expect('FT.SUGGET', 'sug', 'test', 'MAX', i, 'WITHSCORES').equal(expected_res[0:i*2])
env.expect('FT.SUGGET', 'sug', 'test', 'MAX', 10, 'WITHSCORES').equal(expected_res)

def testSuggestMax2(env):
for i in range(10):
env.expect('ft.sugadd', 'sug', 'test %d' % i, 1).equal(i + 1)

expected_res = ['test 0', 'test 1', 'test 2', 'test 3', 'test 4', 'test 5']
for i in range(1,7):
res = env.cmd('FT.SUGGET', 'sug', 'test ', 'MAX', i)
for item in res:
env.assertIn(item, expected_res[0:i])

0 comments on commit ac0973d

Please sign in to comment.