From 4ce3213b1a635d2782c82d86ae41648b021a6ee5 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 13 Oct 2016 12:30:55 +0200 Subject: [PATCH] Searching by character tags honors category selection now --- ZRCola/zrcolachrslct.cpp | 2 +- lib/libZRCola/include/zrcola/tag.h | 4 +++- lib/libZRCola/src/tag.cpp | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ZRCola/zrcolachrslct.cpp b/ZRCola/zrcolachrslct.cpp index 4d5baa9..7062456 100644 --- a/ZRCola/zrcolachrslct.cpp +++ b/ZRCola/zrcolachrslct.cpp @@ -555,7 +555,7 @@ wxThread::ExitCode wxZRColaCharSelect::SearchThread::Entry() // Search by tags: Get tags with given names. Then, get characters of found tags. std::map hits_tag; if (!app->m_tn_db.Search(m_search.c_str(), m_parent->m_locale, hits_tag, TestDestroyS, this)) return (wxThread::ExitCode)1; - if (!app->m_ct_db.Search(hits_tag, hits, TestDestroyS, this)) return (wxThread::ExitCode)1; + if (!app->m_ct_db.Search(hits_tag, app->m_chr_db, m_cats, hits, TestDestroyS, this)) return (wxThread::ExitCode)1; } { diff --git a/lib/libZRCola/include/zrcola/tag.h b/lib/libZRCola/include/zrcola/tag.h index be581f3..eb9bf0f 100644 --- a/lib/libZRCola/include/zrcola/tag.h +++ b/lib/libZRCola/include/zrcola/tag.h @@ -185,11 +185,13 @@ namespace ZRCola { /// Search for characters by tags /// /// \param[in ] tags Search tags + /// \param[in ] ch_db Character database + /// \param[in ] cats Set of categories from \p ch_db, character must be a part of /// \param[inout] hits (character, count) map to append hits to /// \param[in ] fn_abort Pointer to function to periodically test for search cancellation /// \param[in ] cookie Cookie for \p fn_abort call /// - bool Search(_In_ const std::map &tags, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie) = NULL, _In_opt_ void *cookie = NULL) const; + bool Search(_In_ const std::map &tags, _In_ const character_db &ch_db, _In_ const std::set &cats, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie) = NULL, _In_opt_ void *cookie = NULL) const; }; diff --git a/lib/libZRCola/src/tag.cpp b/lib/libZRCola/src/tag.cpp index 222efd1..f393def 100644 --- a/lib/libZRCola/src/tag.cpp +++ b/lib/libZRCola/src/tag.cpp @@ -20,7 +20,7 @@ #include "stdafx.h" -bool ZRCola::chrtag_db::Search(_In_ const std::map &tags, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie), _In_opt_ void *cookie) const +bool ZRCola::chrtag_db::Search(_In_ const std::map &tags, _In_ const character_db &ch_db, _In_ const std::set &cats, _Inout_ std::map &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie), _In_opt_ void *cookie) const { for (auto tag = tags.cbegin(), tag_end = tags.cend(); tag != tag_end; ++tag) { if (fn_abort && fn_abort(cookie)) return false; @@ -32,13 +32,15 @@ bool ZRCola::chrtag_db::Search(_In_ const std::map &t for (size_t i = start; i < end; i++) { if (fn_abort && fn_abort(cookie)) return false; const chrtag &ct = idxTag[i]; - auto idx = hits.find(ct.chr); - if (idx == hits.end()) { - // New character. - hits.insert(std::make_pair(ct.chr, tag->second)); - } else { - // Increase count for existing character. - idx->second += tag->second; + if (cats.find(ch_db.GetCharCat(ct.chr)) != cats.end()) { + auto idx = hits.find(ct.chr); + if (idx == hits.end()) { + // New character. + hits.insert(std::make_pair(ct.chr, tag->second)); + } else { + // Increase count for existing character. + idx->second += tag->second; + } } } }