From 445e7f339ebba3dc90c721adf0207f17464ffec6 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Tue, 31 Jul 2018 10:15:25 +0200 Subject: [PATCH] logic: Fixed full-text search sometimes showing more results than intended * fixed building longest common prefix array for full-text search by making values not relative the the charcode of the "a" character, because this would result in characters (e.g. "_") having a negarive value. --- src/lib/data/fulltextsearch/SuffixArray.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lib/data/fulltextsearch/SuffixArray.cpp b/src/lib/data/fulltextsearch/SuffixArray.cpp index c86de417..c2514f01 100644 --- a/src/lib/data/fulltextsearch/SuffixArray.cpp +++ b/src/lib/data/fulltextsearch/SuffixArray.cpp @@ -26,12 +26,22 @@ void SuffixArray::printArray() const { std::cout << "Suffix Array : \n"; printArr(m_array); + for (int i = 0; i < m_array.size(); i++) + { + std::wstring suffix = m_text.substr(m_array[i]); + std::wcout << i << ": \"" << suffix << "\"" << std::endl; + } } void SuffixArray::printLCP() const { std::cout << "\nLCP Array : \n"; printArr(m_lcp); + for (int i = 0; i < m_array.size(); i++) + { + std::wstring prefix = m_text.substr(m_array[i], m_lcp[i]); + std::wcout << i << ": \"" << prefix << "\"" << std::endl; + } } std::vector SuffixArray::buildLCP() @@ -79,8 +89,8 @@ std::vector SuffixArray::searchForTerm(const std::wstring& searchTerm) cons std::wstring term = searchTerm; std::transform(term.begin(), term.end(), term.begin(), ::towlower); - int termLength = term.length(); - int textLength = m_text.length(); + const int termLength = term.length(); + const int textLength = m_text.length(); int l = -1; int r = textLength; int m; @@ -121,7 +131,7 @@ std::vector SuffixArray::searchForTerm(const std::wstring& searchTerm) cons std::vector SuffixArray::buildSuffixArray() { - int n = m_text.length(); + const int n = m_text.length(); std::vector suffixes; suffixes.reserve(n); @@ -129,8 +139,8 @@ std::vector SuffixArray::buildSuffixArray() for (int i = 0; i < n; i++) { s.index = i; - s.rank[0] = m_text[i] - L'a'; - s.rank[1] = ((i + 1) < n) ? (m_text[i + 1] - L'a') : -1; + s.rank[0] = m_text[i]; + s.rank[1] = ((i + 1) < n) ? (m_text[i + 1]) : -1; suffixes.push_back(s); }