[generator] Create GetUgcForFeature method to reuse it for ugc and rating sections build.

This commit is contained in:
tatiana-yan 2019-04-11 13:09:23 +03:00 committed by mpimenov
parent c198137d69
commit d044e4c0d6
3 changed files with 27 additions and 15 deletions

View file

@ -8,7 +8,6 @@
#include "indexer/feature_data.hpp"
#include "indexer/feature_processor.hpp"
#include "indexer/ftraits.hpp"
#include "base/geo_object_id.hpp"
@ -34,22 +33,12 @@ bool BuildUgcMwmSection(std::string const & srcDbFilename, std::string const & m
std::vector<IndexUGC> content;
feature::ForEachFromDat(mwmFile, [&](FeatureType & f, uint32_t featureId) {
auto const optItem = ftraits::UGC::GetValue(feature::TypesHolder(f));
if (!optItem)
return;
if (!ftraits::UGC::IsUGCAvailable(optItem->m_mask))
return;
auto const it = featureToOsmId.find(featureId);
CHECK(it != featureToOsmId.cend() && it->second.size() != 0,
("FeatureID", featureId, "is not found in", osmToFeatureFilename));
ugc::UGC result;
if (!translator.TranslateUGC(it->second[0], result))
return;
if (result.IsEmpty())
if (!GetUgcForFeature(it->second[0], feature::TypesHolder(f), translator, result))
return;
content.emplace_back(featureId, result);

View file

@ -1,9 +1,9 @@
#include "generator/ugc_translator.hpp"
#include "generator/ugc_db.hpp"
#include "ugc/serdes_json.hpp"
#include "indexer/ftraits.hpp"
#include "coding/string_utf8_multilang.hpp"
#include "base/string_utils.hpp"
@ -51,4 +51,20 @@ void UGCTranslator::CreateDb(std::string const & data)
{
CHECK(m_db.Exec(data), ());
}
bool GetUgcForFeature(base::GeoObjectId const & osmId, feature::TypesHolder const & th,
UGCTranslator & translator, ugc::UGC & result)
{
auto const optItem = ftraits::UGC::GetValue(th);
if (!optItem)
return false;
if (!ftraits::UGC::IsUGCAvailable(optItem->m_mask))
return false;
if (!translator.TranslateUGC(osmId, result))
return false;
return !result.IsEmpty();
}
} // namespace generator

View file

@ -1,11 +1,15 @@
#pragma once
#include "ugc_db.hpp"
#include "generator/ugc_db.hpp"
#include "ugc/types.hpp"
#include "indexer/feature_data.hpp"
#include "base/geo_object_id.hpp"
#include <string>
namespace generator
{
class UGCTranslator
@ -22,4 +26,7 @@ public:
private:
UGCDB m_db;
};
bool GetUgcForFeature(base::GeoObjectId const & osmId, feature::TypesHolder const & th,
UGCTranslator & translator, ugc::UGC & result);
} // namespace generator