summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2023-09-21 17:26:22 +0200
committerGitHub <noreply@github.com>2023-09-21 17:26:22 +0200
commit30d66b745c033484184029fb8bf688b8a79f17d4 (patch)
treea17deca77a8d635f4ff6a0e293dd444f2aafe3a7 /vespalib
parent95daa49ef952798c71b096b28a9ccd3c6f124478 (diff)
parent9edf3caed8ecad63d1f1bb5b07510934690cc6d2 (diff)
Merge pull request #28606 from vespa-engine/geirst/fuzzy-matching-algorithm-query-property
Add query property to control fuzzy matching algorithm.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/fuzzy/CMakeLists.txt1
-rw-r--r--vespalib/src/vespa/vespalib/fuzzy/fuzzy_matching_algorithm.cpp51
-rw-r--r--vespalib/src/vespa/vespalib/fuzzy/fuzzy_matching_algorithm.h26
3 files changed, 78 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/fuzzy/CMakeLists.txt b/vespalib/src/vespa/vespalib/fuzzy/CMakeLists.txt
index bdbb03bcfee..5e8d29980cd 100644
--- a/vespalib/src/vespa/vespalib/fuzzy/CMakeLists.txt
+++ b/vespalib/src/vespa/vespalib/fuzzy/CMakeLists.txt
@@ -3,6 +3,7 @@ vespa_add_library(vespalib_vespalib_fuzzy OBJECT
SOURCES
explicit_levenshtein_dfa.cpp
fuzzy_matcher.cpp
+ fuzzy_matching_algorithm.cpp
implicit_levenshtein_dfa.cpp
levenshtein_dfa.cpp
levenshtein_distance.cpp
diff --git a/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matching_algorithm.cpp b/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matching_algorithm.cpp
new file mode 100644
index 00000000000..826b0beffd6
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matching_algorithm.cpp
@@ -0,0 +1,51 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "fuzzy_matching_algorithm.h"
+
+namespace vespalib {
+
+namespace {
+
+const vespalib::string brute_force = "brute_force";
+const vespalib::string dfa_implicit = "dfa_implicit";
+const vespalib::string dfa_explicit = "dfa_explicit";
+
+}
+
+vespalib::string
+to_string(FuzzyMatchingAlgorithm algo)
+{
+ switch (algo) {
+ case FuzzyMatchingAlgorithm::BruteForce:
+ return brute_force;
+ case FuzzyMatchingAlgorithm::DfaImplicit:
+ return dfa_implicit;
+ case FuzzyMatchingAlgorithm::DfaExplicit:
+ return dfa_explicit;
+ default:
+ return "";
+ }
+}
+
+FuzzyMatchingAlgorithm
+fuzzy_matching_algorithm_from_string(const vespalib::string& algo,
+ FuzzyMatchingAlgorithm default_algo)
+{
+ if (algo == brute_force) {
+ return FuzzyMatchingAlgorithm::BruteForce;
+ } else if (algo == dfa_implicit) {
+ return FuzzyMatchingAlgorithm::DfaImplicit;
+ } else if (algo == dfa_explicit) {
+ return FuzzyMatchingAlgorithm::DfaExplicit;
+ }
+ return default_algo;
+}
+
+std::ostream&
+operator<<(std::ostream& out, FuzzyMatchingAlgorithm algo)
+{
+ out << to_string(algo);
+ return out;
+}
+
+}
diff --git a/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matching_algorithm.h b/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matching_algorithm.h
new file mode 100644
index 00000000000..83cb121fe5f
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matching_algorithm.h
@@ -0,0 +1,26 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/vespalib/stllike/string.h>
+#include <ostream>
+
+namespace vespalib {
+
+/**
+ * Algorithms that are supported for fuzzy matching.
+ */
+enum class FuzzyMatchingAlgorithm {
+ BruteForce,
+ DfaImplicit,
+ DfaExplicit
+};
+
+vespalib::string to_string(FuzzyMatchingAlgorithm algo);
+
+FuzzyMatchingAlgorithm fuzzy_matching_algorithm_from_string(const vespalib::string& algo,
+ FuzzyMatchingAlgorithm default_algo);
+
+std::ostream& operator<<(std::ostream& out, FuzzyMatchingAlgorithm algo);
+
+}