From d5ae272adfb6e2ac41efceb8a7794a90d2483f35 Mon Sep 17 00:00:00 2001 From: Likith B Date: Fri, 9 Aug 2024 11:50:52 +0530 Subject: [PATCH] MB-61640: Fuzzy Dynamic Scoring - Allow edit distances for terms to be read --- automaton.go | 5 +++++ fst_iterator.go | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/automaton.go b/automaton.go index 70398f2..4014797 100644 --- a/automaton.go +++ b/automaton.go @@ -83,3 +83,8 @@ func (m *AlwaysMatch) Accept(int, byte) int { // creating an alwaysMatchAutomaton to avoid unnecessary repeated allocations. var alwaysMatchAutomaton = &AlwaysMatch{} + +type FuzzyAutomaton interface { + Automaton + EditDistance(int) uint8 +} diff --git a/fst_iterator.go b/fst_iterator.go index 1fc2b99..948d1e6 100644 --- a/fst_iterator.go +++ b/fst_iterator.go @@ -16,8 +16,6 @@ package vellum import ( "bytes" - - "github.com/blevesearch/vellum/levenshtein" ) // Iterator represents a means of visiting key/value pairs in order. @@ -219,8 +217,8 @@ OUTER: cmp := bytes.Compare(i.keysStack, i.nextStart) if cmp > 0 { - if dfa, ok := i.aut.(*levenshtein.DFA); ok { - i.keysDistance = dfa.EditDistance(autCurr) + if fa, ok := i.aut.(FuzzyAutomaton); ok { + i.keysDistance = fa.EditDistance(autCurr) } // in final state greater than start key return nil