From 62627079e4d2cf9fdd5618469460ae59cb08255f Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Mon, 2 Dec 2019 18:25:32 +0300 Subject: [PATCH] [generator] Separate path and country parameters for search index build. --- generator/generator_tests_support/test_mwm_builder.cpp | 3 ++- generator/generator_tool/generator_tool.cpp | 2 +- generator/search_index_builder.cpp | 9 ++++++--- generator/search_index_builder.hpp | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/generator/generator_tests_support/test_mwm_builder.cpp b/generator/generator_tests_support/test_mwm_builder.cpp index fbf6a2d8e3..b459f0233a 100644 --- a/generator/generator_tests_support/test_mwm_builder.cpp +++ b/generator/generator_tests_support/test_mwm_builder.cpp @@ -148,7 +148,8 @@ void TestMwmBuilder::Finish() CHECK(indexer::BuildIndexFromDataFile(path, path), ("Can't build geometry index.")); - CHECK(indexer::BuildSearchIndexFromDataFile(path, true /* forceRebuild */, 1 /* threadsCount */), + CHECK(indexer::BuildSearchIndexFromDataFile(m_file.GetDirectory(), m_file.GetCountryName(), + true /* forceRebuild */, 1 /* threadsCount */), ("Can't build search index.")); if (!m_postcodesPath.empty() && m_postcodesCountryInfoGetter) diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index e65fb06fef..f0b8d35104 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -370,7 +370,7 @@ MAIN_WITH_ERROR_HANDLING([](int argc, char ** argv) LOG(LINFO, ("Generating search index for", datFile)); /// @todo Make threads count according to environment (single mwm build or planet build). - if (!indexer::BuildSearchIndexFromDataFile(datFile, true /* forceRebuild */, + if (!indexer::BuildSearchIndexFromDataFile(path, country, true /* forceRebuild */, 1 /* threadsCount */)) { LOG(LCRITICAL, ("Error generating search index.")); diff --git a/generator/search_index_builder.cpp b/generator/search_index_builder.cpp index 45551fde8d..817e867fce 100644 --- a/generator/search_index_builder.cpp +++ b/generator/search_index_builder.cpp @@ -447,7 +447,7 @@ void AddFeatureNameIndexPairs(FeaturesVectorTest const & features, void ReadAddressData(string const & filename, vector & addrs) { - FileReader reader(filename + TEMP_ADDR_FILENAME); + FileReader reader(filename); ReaderSource src(reader); while (src.Size() > 0) { @@ -596,10 +596,12 @@ bool BuildPostcodesImpl(FilesContainerR & container, storage::CountryId const & string const & dataset, string const & tmpFileName, storage::CountryInfoGetter & infoGetter, Writer & indexWriter); -bool BuildSearchIndexFromDataFile(string const & filename, bool forceRebuild, uint32_t threadsCount) +bool BuildSearchIndexFromDataFile(string const & path, string const & country, bool forceRebuild, + uint32_t threadsCount) { Platform & platform = GetPlatform(); + auto const filename = base::JoinPath(path, country + DATA_FILE_EXTENSION); FilesContainerR readContainer(platform.GetReader(filename, "f")); if (readContainer.IsExist(SEARCH_INDEX_FILE_TAG) && !forceRebuild) return true; @@ -612,7 +614,8 @@ bool BuildSearchIndexFromDataFile(string const & filename, bool forceRebuild, ui try { vector addrs; - ReadAddressData(filename, addrs); + auto const addrsFile = base::JoinPath(path, country + DATA_FILE_EXTENSION + TEMP_ADDR_FILENAME); + ReadAddressData(addrsFile, addrs); { FileWriter writer(indexFilePath); BuildSearchIndex(readContainer, addrs, writer); diff --git a/generator/search_index_builder.hpp b/generator/search_index_builder.hpp index 54ef7f9822..e5168392cc 100644 --- a/generator/search_index_builder.hpp +++ b/generator/search_index_builder.hpp @@ -13,8 +13,8 @@ namespace indexer // An attempt to rewrite the search index of an old mwm may result in a future crash // when using search because this function does not update mwm's version. This results // in version mismatch when trying to read the index. -bool BuildSearchIndexFromDataFile(std::string const & filename, bool forceRebuild, - uint32_t threadsCount); +bool BuildSearchIndexFromDataFile(std::string const & path, std::string const & country, + bool forceRebuild, uint32_t threadsCount); // Builds postcodes section with external postcodes data and writes it to the mwm file. bool BuildPostcodes(std::string const & path, std::string const & country,