From baf28eced5c000057c3048a2d97b4cb386ff907c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 30 Mar 2022 22:04:10 +0800 Subject: [PATCH] add fuzzy search --- source/libs/index/src/indexFstDfa.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/source/libs/index/src/indexFstDfa.c b/source/libs/index/src/indexFstDfa.c index e704144974..b4ac9f3a99 100644 --- a/source/libs/index/src/indexFstDfa.c +++ b/source/libs/index/src/indexFstDfa.c @@ -165,15 +165,34 @@ FstDfa *dfaCreate(SArray *insts, SArray *states) { return dfa; } bool dfaIsMatch(FstDfa *dfa, uint32_t si) { - // impl match - return true; + if (dfa->states == NULL || si < taosArrayGetSize(dfa->states)) { + return false; + } + State *st = taosArrayGet(dfa->states, si); + return st != NULL ? st->isMatch : false; } bool dfaAccept(FstDfa *dfa, uint32_t si, uint8_t byte, uint32_t *result) { - // impl accept + if (dfa->states == NULL || si < taosArrayGetSize(dfa->states)) { + return false; + } + State *st = taosArrayGet(dfa->states, si); + *result = st->next[byte]; return true; } void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip) { - // impl add + if (sparSetContains(set, ip)) { + return; + } + sparSetAdd(set, ip); + Inst *inst = taosArrayGet(dfa->insts, ip); + if (inst->ty == MATCH || inst->ty == RANGE) { + // do nothing + } else if (inst->ty == JUMP) { + dfaAdd(dfa, set, inst->jv.step); + } else if (inst->ty == SPLIT) { + dfaAdd(dfa, set, inst->sv.len1); + dfaAdd(dfa, set, inst->sv.len2); + } return; } bool dfaRun(FstDfa *dfa, FstSparseSet *from, FstSparseSet *to, uint8_t byte) {