diff options
author | vng <viktor.govako@gmail.com> | 2012-03-03 04:13:29 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:36:15 +0300 |
commit | 54165b2adf30ee08717c1136ce83894f2325d5ca (patch) | |
tree | 73ca7ea45fa0bfe019214f27c3e053660d30c98d /indexer | |
parent | 0af97743edc0e1f3deaab049c36b4a5f84145aff (diff) |
[search] Add only categorized features to search index. Do not add some categories of features without names to search index.
Diffstat (limited to 'indexer')
-rw-r--r-- | indexer/categories_holder.hpp | 10 | ||||
-rw-r--r-- | indexer/feature_loader_base.hpp | 1 | ||||
-rw-r--r-- | indexer/features_vector.hpp | 6 | ||||
-rw-r--r-- | indexer/search_index_builder.cpp | 94 | ||||
-rw-r--r-- | indexer/search_index_builder.hpp | 6 |
5 files changed, 69 insertions, 48 deletions
diff --git a/indexer/categories_holder.hpp b/indexer/categories_holder.hpp index 552b60a3f4..71f96452dc 100644 --- a/indexer/categories_holder.hpp +++ b/indexer/categories_holder.hpp @@ -73,8 +73,18 @@ public: } } + /// Search name for type with preffered language. + /// If no name for this language, return first (en) name. + /// @return false if no categories for type. bool GetNameByType(uint32_t type, int8_t lang, string & name) const; + inline bool IsTypeExist(uint32_t type) const + { + // pass any language + string dummy; + return GetNameByType(type, 0, dummy); + } + inline void Swap(CategoriesHolder & r) { m_type2cat.swap(r.m_type2cat); diff --git a/indexer/feature_loader_base.hpp b/indexer/feature_loader_base.hpp index 55fccbd396..962e8d71be 100644 --- a/indexer/feature_loader_base.hpp +++ b/indexer/feature_loader_base.hpp @@ -41,7 +41,6 @@ namespace feature inline int GetScalesCount() const { return static_cast<int>(m_header.GetScalesCount()); } inline int GetScale(int i) const { return m_header.GetScale(i); } inline int GetLastScale() const { return m_header.GetLastScale(); } - inline pair<int, int> GetScaleRange() const { return m_header.GetScaleRange(); } }; class LoaderBase diff --git a/indexer/features_vector.hpp b/indexer/features_vector.hpp index 92766a1e8a..c66bbd1bee 100644 --- a/indexer/features_vector.hpp +++ b/indexer/features_vector.hpp @@ -28,12 +28,6 @@ public: m_RecordReader.ForEachRecord(DoGetFeatures<ToDo>(m_LoadInfo, toDo)); } - inline serial::CodingParams const & GetCodingParams() const - { - return m_LoadInfo.GetDefCodingParams(); - } - inline pair<int, int> GetScaleRange() const { return m_LoadInfo.GetScaleRange(); } - private: template <class ToDo> class DoGetFeatures { diff --git a/indexer/search_index_builder.cpp b/indexer/search_index_builder.cpp index f1bfccc649..43dad95ec6 100644 --- a/indexer/search_index_builder.cpp +++ b/indexer/search_index_builder.cpp @@ -8,6 +8,7 @@ #include "string_file.hpp" #include "classificator.hpp" #include "feature_visibility.hpp" +#include "categories_holder.hpp" #include "../defines.hpp" @@ -64,6 +65,8 @@ class FeatureInserter { StringsFile & m_names; + CategoriesHolder const & m_categories; + typedef StringsFile::ValueT ValueT; typedef search::trie::ValueReader SaverT; SaverT m_valueSaver; @@ -185,42 +188,52 @@ class FeatureInserter class AvoidEmptyName { - vector<uint32_t> m_vec; + vector<uint32_t> m_match[2]; - public: - AvoidEmptyName() + template <size_t count, size_t ind> + void FillMatch(char const * (& arr)[count][ind]) { - char const * arr[][3] = { - { "place", "city", ""}, - { "place", "city", "capital"}, - { "place", "town", ""}, - { "place", "county", ""}, - { "place", "state", ""}, - { "place", "region", ""} - }; + STATIC_ASSERT ( count > 0 ); + STATIC_ASSERT ( ind > 0 ); Classificator const & c = classif(); - size_t const count = ARRAY_SIZE(arr); - m_vec.reserve(count); - + m_match[ind-1].reserve(count); for (size_t i = 0; i < count; ++i) { - vector<string> v; - v.push_back(arr[i][0]); - v.push_back(arr[i][1]); - if (strlen(arr[i][2]) > 0) - v.push_back(arr[i][2]); - - m_vec.push_back(c.GetTypeByPath(v)); + vector<string> v(arr[i], arr[i] + ind); + m_match[ind-1].push_back(c.GetTypeByPath(v)); } } + public: + AvoidEmptyName() + { + char const * arr1[][1] = { { "highway" }, { "natural" }, { "waterway"} }; + + char const * arr2[][2] = { + { "place", "city" }, + { "place", "town" }, + { "place", "county" }, + { "place", "state" }, + { "place", "region" } + }; + + FillMatch(arr1); + FillMatch(arr2); + } + bool IsExist(feature::TypesHolder const & types) const { - for (size_t i = 0; i < m_vec.size(); ++i) - if (types.Has(m_vec[i])) - return true; + for (size_t i = 0; i < types.Size(); ++i) + for (size_t j = 0; j < ARRAY_SIZE(m_match); ++j) + { + uint32_t type = types[i]; + ftype::TruncValue(type, j+1); + + if (find(m_match[j].begin(), m_match[j].end(), type) != m_match[j].end()) + return true; + } return false; } @@ -228,9 +241,10 @@ class FeatureInserter public: FeatureInserter(StringsFile & names, + CategoriesHolder const & catHolder, serial::CodingParams const & cp, pair<int, int> const & scales) - : m_names(names), m_valueSaver(cp), m_scales(scales) + : m_names(names), m_categories(catHolder), m_valueSaver(cp), m_scales(scales) { } @@ -262,6 +276,10 @@ public: // highway-primary-oneway or amenity-parking-fee. ftype::TruncValue(type, 2); + // Push to index only categorized types. + if (!m_categories.IsTypeExist(type)) + continue; + // Do index only for visible types in mwm. pair<int, int> const r = feature::DrawableScaleRangeForType(type); if (my::between_s(m_scales.first, m_scales.second, r.first) || @@ -273,16 +291,19 @@ public: } }; -} // unnamed namespace - -void indexer::BuildSearchIndex(FeaturesVector const & featuresV, Writer & writer, - string const & tmpFilePath) +void BuildSearchIndex(FilesContainerR const & cont, CategoriesHolder const & catHolder, + Writer & writer, string const & tmpFilePath) { { + feature::DataHeader header; + header.Load(cont.GetReader(HEADER_FILE_TAG)); + FeaturesVector featuresV(cont, header); + + serial::CodingParams cp(search::GetCPForTrie(header.GetDefCodingParams())); + StringsFile names(tmpFilePath); - serial::CodingParams cp(search::GetCPForTrie(featuresV.GetCodingParams())); - featuresV.ForEachOffset(FeatureInserter(names, cp, featuresV.GetScaleRange())); + featuresV.ForEachOffset(FeatureInserter(names, catHolder, cp, header.GetScaleRange())); names.EndAdding(); names.OpenForRead(); @@ -295,6 +316,8 @@ void indexer::BuildSearchIndex(FeaturesVector const & featuresV, Writer & writer FileWriter::DeleteFileX(tmpFilePath); } +} + bool indexer::BuildSearchIndexFromDatFile(string const & fName, bool forceRebuild) { LOG(LINFO, ("Start building search index. Bits = ", search::POINT_CODING_BITS)); @@ -311,13 +334,12 @@ bool indexer::BuildSearchIndexFromDatFile(string const & fName, bool forceRebuil if (!forceRebuild && readCont.IsReaderExist(SEARCH_INDEX_FILE_TAG)) return true; - feature::DataHeader header; - header.Load(readCont.GetReader(HEADER_FILE_TAG)); + FileWriter writer(tmpFile); - FeaturesVector featuresVector(readCont, header); + CategoriesHolder catHolder(pl.GetReader(SEARCH_CATEGORIES_FILE_NAME)); - FileWriter writer(tmpFile); - BuildSearchIndex(featuresVector, writer, pl.WritablePathForFile(fName + ".search_index_1.tmp")); + BuildSearchIndex(readCont, catHolder, writer, + pl.WritablePathForFile(fName + ".search_index_1.tmp")); LOG(LINFO, ("Search index size = ", writer.Size())); } diff --git a/indexer/search_index_builder.hpp b/indexer/search_index_builder.hpp index baaed3d6c8..41ea88b8cb 100644 --- a/indexer/search_index_builder.hpp +++ b/indexer/search_index_builder.hpp @@ -1,12 +1,8 @@ #pragma once #include "../std/string.hpp" -class FeaturesVector; -class Writer; namespace indexer { - void BuildSearchIndex(FeaturesVector const & featuresVector, Writer & writer, - string const & tmpFilePath); bool BuildSearchIndexFromDatFile(string const & fName, bool forceRebuild = false); -} // namespace indexer +} |