Skip to content

Commit

Permalink
Fix FT.EXPLAIN, FT.EXPLAINCLI: INFIX, SUFFIX (#4477)
Browse files Browse the repository at this point in the history
(cherry picked from commit be5c7c1)
  • Loading branch information
nafraf committed Feb 19, 2024
1 parent a6600ae commit 71965a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/query.c
Expand Up @@ -1644,7 +1644,13 @@ static sds QueryNode_DumpSds(sds s, const IndexSpec *spec, const QueryNode *qs,
return s;

case QN_PREFIX:
s = sdscatprintf(s, "PREFIX{%s*", (char *)qs->pfx.tok.str);
if(qs->pfx.prefix && qs->pfx.suffix) {
s = sdscatprintf(s, "INFIX{*%s*", (char *)qs->pfx.tok.str);
} else if (qs->pfx.suffix) {
s = sdscatprintf(s, "SUFFIX{*%s", (char *)qs->pfx.tok.str);
} else {
s = sdscatprintf(s, "PREFIX{%s*", (char *)qs->pfx.tok.str);
}
break;

case QN_LEXRANGE:
Expand Down
13 changes: 13 additions & 0 deletions tests/pytests/test_issues.py
Expand Up @@ -968,3 +968,16 @@ def test_mod_6557(env: Env):
).ok()
# Verify that `FT.SEARCH` queries are not hanging and return an error
env.expect('FT.SEARCH', 'idx', '*').error().contains('Could not send query to cluster')

def test_mod6186(env):
env.expect('FT.CREATE idx SCHEMA txt1 TEXT').equal('OK')
env.expect('FT.EXPLAIN idx abc*').equal('PREFIX{abc*}\n')
env.expect('FT.EXPLAIN idx *abc').equal('SUFFIX{*abc}\n')
env.expect('FT.EXPLAIN idx *abc*').equal('INFIX{*abc*}\n')

if not env.isCluster():
# FT.EXPLAINCLI is not supported by the coordinator
env.expect('FT.EXPLAINCLI idx abc*').equal(['PREFIX{abc*}', ''])
env.expect('FT.EXPLAINCLI idx *abc').equal(['SUFFIX{*abc}', ''])
env.expect('FT.EXPLAINCLI idx *abc*').equal(['INFIX{*abc*}', ''])

0 comments on commit 71965a0

Please sign in to comment.