From f2c9f40dffca587d89bc321d8ff53ce48fff71fe Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 31 Mar 2022 10:16:04 +0800 Subject: [PATCH] add fuzzy search --- source/libs/index/src/indexFstDfa.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/source/libs/index/src/indexFstDfa.c b/source/libs/index/src/indexFstDfa.c index b4ac9f3a99..ff6b154c54 100644 --- a/source/libs/index/src/indexFstDfa.c +++ b/source/libs/index/src/indexFstDfa.c @@ -193,9 +193,26 @@ void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip) { dfaAdd(dfa, set, inst->sv.len1); dfaAdd(dfa, set, inst->sv.len2); } + return; } bool dfaRun(FstDfa *dfa, FstSparseSet *from, FstSparseSet *to, uint8_t byte) { - // impl run - return true; + bool isMatch = false; + sparSetClear(to); + for (int i = 0; i < sparSetLen(from); i++) { + uint32_t ip = sparSetGet(from, i); + + Inst *inst = taosArrayGet(dfa->insts, ip); + if (inst->ty == JUMP || inst->ty == SPLIT) { + continue; + } else if (inst->ty == MATCH) { + isMatch = true; + } else if (inst->ty == RANGE) { + if (inst->rv.start <= byte && byte <= inst->rv.end) { + dfaAdd(dfa, to, ip + 1); + } + } + } + + return isMatch; }