forked from organicmaps/organicmaps
[search] Some fixes.
This commit is contained in:
parent
8c24fdf040
commit
55dbe694da
2 changed files with 48 additions and 15 deletions
|
@ -13,6 +13,8 @@
|
|||
#include "../std/utility.hpp"
|
||||
#include "../std/vector.hpp"
|
||||
|
||||
//#include "../sparsehash/dense_hash_set.hpp"
|
||||
|
||||
|
||||
namespace search
|
||||
{
|
||||
|
@ -176,10 +178,21 @@ template <class FilterT> class OffsetIntersecter
|
|||
scoped_ptr<SetType> m_prevSet;
|
||||
scoped_ptr<SetType> m_set;
|
||||
|
||||
void InitSet(scoped_ptr<SetType> & ptr)
|
||||
{
|
||||
ptr.reset(new SetType());
|
||||
|
||||
// this is not std compatible, but important for google::dense_hash_set
|
||||
//ValueT zero;
|
||||
//zero.m_featureId = 0;
|
||||
//ptr->set_empty_key(zero);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit OffsetIntersecter(FilterT const & filter)
|
||||
: m_filter(filter), m_set(new SetType())
|
||||
: m_filter(filter)
|
||||
{
|
||||
InitSet(m_set);
|
||||
}
|
||||
|
||||
void operator() (ValueT const & v)
|
||||
|
@ -196,7 +209,7 @@ public:
|
|||
void NextStep()
|
||||
{
|
||||
if (!m_prevSet)
|
||||
m_prevSet.reset(new SetType());
|
||||
InitSet(m_prevSet);
|
||||
|
||||
m_prevSet.swap(m_set);
|
||||
m_set->clear();
|
||||
|
@ -293,11 +306,11 @@ void MatchFeaturesInTrie(vector<vector<strings::UniString> > const & tokens,
|
|||
// match in trie
|
||||
impl::FullMatchInTrie(trieRoot.m_root, trieRoot.m_prefix, trieRoot.m_prefixSize,
|
||||
tokens[i][j], intersecter);
|
||||
|
||||
// get additional features for token
|
||||
addHolder.GetValues(i, intersecter);
|
||||
}
|
||||
|
||||
// get additional features for 'i' token
|
||||
addHolder.GetValues(i, intersecter);
|
||||
|
||||
intersecter.NextStep();
|
||||
}
|
||||
|
||||
|
@ -310,13 +323,15 @@ void MatchFeaturesInTrie(vector<vector<strings::UniString> > const & tokens,
|
|||
// match in trie
|
||||
impl::PrefixMatchInTrie(trieRoot.m_root, trieRoot.m_prefix, trieRoot.m_prefixSize,
|
||||
prefixTokens[i], intersecter);
|
||||
|
||||
// get additional features for token
|
||||
addHolder.GetValues(count, intersecter);
|
||||
}
|
||||
|
||||
if (prefixCount > 0)
|
||||
{
|
||||
// get additional features for prefix token
|
||||
addHolder.GetValues(count, intersecter);
|
||||
|
||||
intersecter.NextStep();
|
||||
}
|
||||
|
||||
intersecter.ForEachResult(toDo);
|
||||
}
|
||||
|
|
|
@ -171,6 +171,7 @@ void Query::SetPreferredLanguage(string const & lang)
|
|||
|
||||
void Query::SetInputLanguage(int8_t lang)
|
||||
{
|
||||
LOG(LDEBUG, ("New input language = ", lang));
|
||||
SetLanguage(LANG_INPUT, lang);
|
||||
}
|
||||
|
||||
|
@ -796,6 +797,16 @@ namespace impl
|
|||
};
|
||||
|
||||
void swap(Locality & r1, Locality & r2) { r1.Swap(r2); }
|
||||
|
||||
string DebugPrint(Locality const & l)
|
||||
{
|
||||
string res("Locality: ");
|
||||
res += "Name: " + l.m_name;
|
||||
res += "; Name English: " + l.m_enName;
|
||||
res += "; Rank: " + ::DebugPrint(l.m_value.m_rank);
|
||||
res += "; Matched: " + ::DebugPrint(l.m_matchedTokens.size());
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
void Query::SearchAddress()
|
||||
|
@ -891,21 +902,25 @@ namespace impl
|
|||
}
|
||||
};
|
||||
|
||||
int8_t m_lang, m_en, m_int;
|
||||
int8_t m_lang;
|
||||
int8_t m_arrEn[3];
|
||||
|
||||
void AssignEnglishName(FeatureType const & f, Locality & l)
|
||||
{
|
||||
if (!f.GetName(m_en, l.m_enName))
|
||||
(void)f.GetName(m_int, l.m_enName);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
if (f.GetName(m_arrEn[i], l.m_enName))
|
||||
break;
|
||||
}
|
||||
|
||||
volatile bool & m_isCancelled;
|
||||
|
||||
public:
|
||||
DoFindLocality(MwmValue * pMwm, int8_t lang, volatile bool & isCancelled)
|
||||
DoFindLocality(Query & q, MwmValue * pMwm, int8_t lang, volatile bool & isCancelled)
|
||||
: m_vector(pMwm->m_cont, pMwm->GetHeader()), m_lang(lang), m_isCancelled(isCancelled)
|
||||
{
|
||||
m_en = StringUtf8Multilang::GetLangIndex("en");
|
||||
m_int = StringUtf8Multilang::GetLangIndex("int_name");
|
||||
m_arrEn[0] = q.GetLanguage(LANG_ENGLISH);
|
||||
m_arrEn[1] = q.GetLanguage(LANG_INTERNATIONAL);
|
||||
m_arrEn[2] = q.GetLanguage(LANG_DEFAULT);
|
||||
}
|
||||
|
||||
void Resize(size_t) {}
|
||||
|
@ -983,14 +998,17 @@ bool Query::SearchLocality(MwmValue * pMwm, impl::Locality & res)
|
|||
{
|
||||
scoped_ptr<TrieIterator> pLangRoot(pTrieRoot->GoToEdge(i));
|
||||
|
||||
impl::DoFindLocality doFind(pMwm, lang, m_cancel);
|
||||
impl::DoFindLocality doFind(*this, pMwm, lang, m_cancel);
|
||||
GetFeaturesInTrie(params.m_tokens, params.m_prefixTokens,
|
||||
TrieRootPrefix(*pLangRoot, edge), doFind);
|
||||
|
||||
// save better locality, if any
|
||||
impl::Locality loc;
|
||||
if (doFind.GetBestLocality(loc) && (res < loc))
|
||||
{
|
||||
LOG(LDEBUG, ("Better location ", loc, " for lang ", lang));
|
||||
res = loc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue