Searching by character tags honors category selection now

This commit is contained in:
Simon Rozman 2016-10-13 12:30:55 +02:00
parent 75b2758797
commit 4ce3213b1a
3 changed files with 14 additions and 10 deletions

View File

@ -555,7 +555,7 @@ wxThread::ExitCode wxZRColaCharSelect::SearchThread::Entry()
// Search by tags: Get tags with given names. Then, get characters of found tags. // Search by tags: Get tags with given names. Then, get characters of found tags.
std::map<ZRCola::tagid_t, unsigned __int16> hits_tag; std::map<ZRCola::tagid_t, unsigned __int16> 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_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;
} }
{ {

View File

@ -185,11 +185,13 @@ namespace ZRCola {
/// Search for characters by tags /// Search for characters by tags
/// ///
/// \param[in ] tags Search 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[inout] hits (character, count) map to append hits to
/// \param[in ] fn_abort Pointer to function to periodically test for search cancellation /// \param[in ] fn_abort Pointer to function to periodically test for search cancellation
/// \param[in ] cookie Cookie for \p fn_abort call /// \param[in ] cookie Cookie for \p fn_abort call
/// ///
bool Search(_In_ const std::map<tagid_t, unsigned __int16> &tags, _Inout_ std::map<wchar_t, charrank_t> &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie) = NULL, _In_opt_ void *cookie = NULL) const; bool Search(_In_ const std::map<tagid_t, unsigned __int16> &tags, _In_ const character_db &ch_db, _In_ const std::set<chrcatid_t> &cats, _Inout_ std::map<wchar_t, charrank_t> &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie) = NULL, _In_opt_ void *cookie = NULL) const;
}; };

View File

@ -20,7 +20,7 @@
#include "stdafx.h" #include "stdafx.h"
bool ZRCola::chrtag_db::Search(_In_ const std::map<tagid_t, unsigned __int16> &tags, _Inout_ std::map<wchar_t, charrank_t> &hits, _In_opt_ bool (__cdecl *fn_abort)(void *cookie), _In_opt_ void *cookie) const bool ZRCola::chrtag_db::Search(_In_ const std::map<tagid_t, unsigned __int16> &tags, _In_ const character_db &ch_db, _In_ const std::set<chrcatid_t> &cats, _Inout_ std::map<wchar_t, charrank_t> &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) { for (auto tag = tags.cbegin(), tag_end = tags.cend(); tag != tag_end; ++tag) {
if (fn_abort && fn_abort(cookie)) return false; if (fn_abort && fn_abort(cookie)) return false;
@ -32,6 +32,7 @@ bool ZRCola::chrtag_db::Search(_In_ const std::map<tagid_t, unsigned __int16> &t
for (size_t i = start; i < end; i++) { for (size_t i = start; i < end; i++) {
if (fn_abort && fn_abort(cookie)) return false; if (fn_abort && fn_abort(cookie)) return false;
const chrtag &ct = idxTag[i]; const chrtag &ct = idxTag[i];
if (cats.find(ch_db.GetCharCat(ct.chr)) != cats.end()) {
auto idx = hits.find(ct.chr); auto idx = hits.find(ct.chr);
if (idx == hits.end()) { if (idx == hits.end()) {
// New character. // New character.
@ -43,6 +44,7 @@ bool ZRCola::chrtag_db::Search(_In_ const std::map<tagid_t, unsigned __int16> &t
} }
} }
} }
}
return true; return true;
} }