[search] Added a test for villages.

This commit is contained in:
Maxim Pimenov 2016-01-26 19:14:10 +03:00 committed by Sergey Yershov
parent 4594fae432
commit 77dabd4807
9 changed files with 92 additions and 39 deletions

View file

@ -364,7 +364,10 @@ void BuildAddressTable(FilesContainerR & container, Writer & writer)
LOG(LINFO, ("Address: Building -> Street (opt, all)", building2Street.GetCount()));
}
LOG(LINFO, ("Address: Matched percent", 100 * (1.0 - missing/double(address))));
double matchedPercent = 100;
if (address > 0)
matchedPercent = 100.0 * (1.0 - static_cast<double>(missing) / static_cast<double>(address));
LOG(LINFO, ("Address: Matched percent", matchedPercent));
LOG(LINFO, ("Address: Upper bounds", bounds));
}
} // namespace

View file

@ -76,16 +76,12 @@ UNIT_TEST(SearchQueryV2_Smoke)
make_unique<TestSearchQueryFactory>());
auto const wonderlandCountry =
make_shared<TestCountry>(m2::PointD(10, 10), "Wonderland", "en");
auto const losAlamosCity =
make_shared<TestCity>(m2::PointD(10, 10), "Los Alamos", "en", 100 /* rank */);
auto const mskCity = make_shared<TestCity>(m2::PointD(0, 0), "Moscow", "en", 100 /* rank */);
auto const busStop = make_shared<TestPOI>(m2::PointD(0, 0), "Bus stop", "en");
auto const tramStop = make_shared<TestPOI>(m2::PointD(0.0001, 0.0001), "Tram stop", "en");
auto const quantumTeleport1 =
make_shared<TestPOI>(m2::PointD(0.0002, 0.0002), "Quantum teleport 1", "en");
auto const quantumTeleport2 =
make_shared<TestPOI>(m2::PointD(10, 10), "Quantum teleport 2", "en");
auto const quantumCafe = make_shared<TestPOI>(m2::PointD(-0.0002, -0.0002), "Quantum cafe", "en");
auto const longPondVillage = make_shared<TestCity>(m2::PointD(15, 15), "Long Pond Village", "en", 10 /* rank */);
auto const feynmanStreet = make_shared<TestStreet>(
vector<m2::PointD>{m2::PointD(9.999, 9.999), m2::PointD(10, 10), m2::PointD(10.001, 10.001)},
"Feynman street", "en");
@ -98,17 +94,29 @@ UNIT_TEST(SearchQueryV2_Smoke)
auto const bohrStreet3 = make_shared<TestStreet>(
vector<m2::PointD>{m2::PointD(10.002, 9.998), m2::PointD(10.003, 9.997)}, "Bohr street",
"en");
auto const firstAprilStreet = make_shared<TestStreet>(
vector<m2::PointD>{m2::PointD(14.998, 15), m2::PointD(15.002, 15)}, "1st April street",
"en");
auto const feynmanHouse = make_shared<TestBuilding>(m2::PointD(10, 10), "Feynman house",
"1 unit 1", *feynmanStreet, "en");
auto const bohrHouse =
make_shared<TestBuilding>(m2::PointD(10, 10), "Bohr house", "1 unit 1", *bohrStreet1, "en");
auto const hilbertHouse = make_shared<TestBuilding>(
vector<m2::PointD>{
{10.0005, 10.0005}, {10.0006, 10.0005}, {10.0006, 10.0006}, {10.0005, 10.0006}},
"Hilbert house", "1 unit 2", *bohrStreet1, "en");
auto const descartesHouse =
make_shared<TestBuilding>(m2::PointD(10, 10), "Descartes house", "2", "en");
auto const bornHouse = make_shared<TestBuilding>(m2::PointD(14.999, 15), "Born house", "8", *firstAprilStreet, "en");
auto const busStop = make_shared<TestPOI>(m2::PointD(0, 0), "Bus stop", "en");
auto const tramStop = make_shared<TestPOI>(m2::PointD(0.0001, 0.0001), "Tram stop", "en");
auto const quantumTeleport1 =
make_shared<TestPOI>(m2::PointD(0.0002, 0.0002), "Quantum teleport 1", "en");
auto const quantumTeleport2 =
make_shared<TestPOI>(m2::PointD(10, 10), "Quantum teleport 2", "en");
auto const quantumCafe = make_shared<TestPOI>(m2::PointD(-0.0002, -0.0002), "Quantum cafe", "en");
auto const lantern1 = make_shared<TestPOI>(m2::PointD(10.0005, 10.0005), "lantern 1", "en");
auto const lantern2 = make_shared<TestPOI>(m2::PointD(10.0006, 10.0005), "lantern 2", "en");
@ -116,23 +124,27 @@ UNIT_TEST(SearchQueryV2_Smoke)
TestMwmBuilder builder(wonderland, feature::DataHeader::country);
builder.Add(*losAlamosCity);
builder.Add(*mskCity);
builder.Add(*longPondVillage);
builder.Add(*feynmanStreet);
builder.Add(*bohrStreet1);
builder.Add(*bohrStreet2);
builder.Add(*bohrStreet3);
builder.Add(*firstAprilStreet);
builder.Add(*feynmanHouse);
builder.Add(*bohrHouse);
builder.Add(*hilbertHouse);
builder.Add(*descartesHouse);
builder.Add(*bornHouse);
builder.Add(*busStop);
builder.Add(*tramStop);
builder.Add(*quantumTeleport1);
builder.Add(*quantumTeleport2);
builder.Add(*quantumCafe);
builder.Add(*feynmanStreet);
builder.Add(*bohrStreet1);
builder.Add(*bohrStreet2);
builder.Add(*bohrStreet3);
builder.Add(*feynmanHouse);
builder.Add(*bohrHouse);
builder.Add(*hilbertHouse);
builder.Add(*lantern1);
builder.Add(*lantern2);
builder.Add(*descartesHouse);
}
{
@ -140,6 +152,7 @@ UNIT_TEST(SearchQueryV2_Smoke)
builder.Add(*wonderlandCountry);
builder.Add(*losAlamosCity);
builder.Add(*mskCity);
builder.Add(*longPondVillage);
}
auto const wonderlandResult = engine.RegisterMap(wonderland);
@ -254,4 +267,11 @@ UNIT_TEST(SearchQueryV2_Smoke)
make_shared<ExactMatch>(wonderlandId, quantumTeleport2)};
TEST(MatchResults(engine, rules, request.Results()), ());
}
{
TestSearchRequest request(engine, "long pond 1st april street 8", "en", search::SearchParams::ALL, viewport);
request.Wait();
vector<shared_ptr<MatchingRule>> rules = {make_shared<ExactMatch>(wonderlandId, bornHouse)};
TEST(MatchResults(engine, rules, request.Results()), ());
}
}

View file

@ -103,6 +103,28 @@ string TestCity::ToString() const
return os.str();
}
// TestVillage ----------------------------------------------------------------------------------------
TestVillage::TestVillage(m2::PointD const & center, string const & name, string const & lang,
uint8_t rank)
: TestFeature(center, name, lang), m_rank(rank)
{
}
void TestVillage::Serialize(FeatureBuilder1 & fb) const
{
TestFeature::Serialize(fb);
auto const & classificator = classif();
fb.SetType(classificator.GetTypeByPath({"place", "village"}));
fb.SetRank(m_rank);
}
string TestVillage::ToString() const
{
ostringstream os;
os << "TestVillage [" << m_name << ", " << m_lang << ", " << DebugPrint(m_center) << "]";
return os.str();
}
// TestStreet --------------------------------------------------------------------------------------
TestStreet::TestStreet(vector<m2::PointD> const & points, string const & name, string const & lang)
: TestFeature(name, lang), m_points(points)

View file

@ -66,6 +66,19 @@ private:
uint8_t const m_rank;
};
class TestVillage : public TestFeature
{
public:
TestVillage(m2::PointD const & center, string const & name, string const & lang, uint8_t rank);
// TestFeature overrides:
void Serialize(FeatureBuilder1 & fb) const override;
string ToString() const override;
private:
uint8_t const m_rank;
};
class TestStreet : public TestFeature
{
public:

View file

@ -70,6 +70,7 @@ public:
{
case SearchModel::SEARCH_TYPE_POI:
case SearchModel::SEARCH_TYPE_CITY:
case SearchModel::SEARCH_TYPE_VILLAGE:
case SearchModel::SEARCH_TYPE_STATE:
case SearchModel::SEARCH_TYPE_COUNTRY:
case SearchModel::SEARCH_TYPE_COUNT:

View file

@ -551,7 +551,7 @@ void Geocoder::ClearCaches()
m_addressFeatures.clear();
m_matchersCache.clear();
m_streetsCache.clear();
m_villagesCache.clear();
m_villages.reset();
}
void Geocoder::PrepareRetrievalParams(size_t curToken, size_t endToken)
@ -758,7 +758,7 @@ void Geocoder::FillLocalitiesTable()
void Geocoder::FillVillageLocalities()
{
vector<Locality> preLocalities;
FillLocalityCandidates(m_villages, kMaxNumVillages, preLocalities);
FillLocalityCandidates(m_villages.get(), kMaxNumVillages, preLocalities);
size_t numVillages = 0;
@ -1240,21 +1240,12 @@ coding::CompressedBitVector const * Geocoder::LoadStreets(MwmContext & context)
return result;
}
coding::CompressedBitVector const * Geocoder::LoadVillages(MwmContext & context)
unique_ptr<coding::CompressedBitVector> Geocoder::LoadVillages(MwmContext & context)
{
if (!context.m_handle.IsAlive() || !HasSearchIndex(context.m_value))
return nullptr;
return make_unique<coding::DenseCBV>();
auto mwmId = context.m_handle.GetId();
auto const it = m_villagesCache.find(mwmId);
if (it != m_villagesCache.cend())
return it->second.get();
auto villages = LoadCategories(context, GetVillageCategories());
auto const * result = villages.get();
m_villagesCache[mwmId] = move(villages);
return result;
return LoadCategories(context, GetVillageCategories());
}
coding::CompressedBitVector const * Geocoder::RetrieveGeometryFeatures(MwmContext const & context,

View file

@ -118,8 +118,11 @@ private:
RegionType m_type;
};
// This struct represents a city. It is used to filter features
// This struct represents a city or a village. It is used to filter features
// during search.
// todo(@m) It works well as is, but consider a new naming scheme
// when counties etc. are added. E.g., Region for countries and
// states and Locality for smaller settlements.
struct City : public Locality
{
City(Locality const & l): Locality(l) {}
@ -197,7 +200,7 @@ private:
coding::CompressedBitVector const * LoadStreets(MwmContext & context);
coding::CompressedBitVector const * LoadVillages(MwmContext & context);
unique_ptr<coding::CompressedBitVector> LoadVillages(MwmContext & context);
/// A caching wrapper around Retrieval::RetrieveGeometryFeatures.
/// param[in] Optional query id. Use VIEWPORT_ID, POSITION_ID or feature index for locality.
@ -252,14 +255,11 @@ private:
// Cache of street ids in mwms.
map<MwmSet::MwmId, unique_ptr<coding::CompressedBitVector>> m_streetsCache;
// Cache of village ids in mwms.
map<MwmSet::MwmId, unique_ptr<coding::CompressedBitVector>> m_villagesCache;
// Street features in the mwm that is currently being processed.
coding::CompressedBitVector const * m_streets;
// Village features in the mwm that is currently being processed.
coding::CompressedBitVector const * m_villages;
unique_ptr<coding::CompressedBitVector> m_villages;
// This vector is used to indicate what tokens were matched by
// locality and can't be re-used during the geocoding process.

View file

@ -29,6 +29,7 @@ void IntersectionResult::Set(SearchModel::SearchType type, uint32_t id)
m_street = id;
break;
case SearchModel::SEARCH_TYPE_CITY:
case SearchModel::SEARCH_TYPE_VILLAGE:
case SearchModel::SEARCH_TYPE_STATE:
case SearchModel::SEARCH_TYPE_COUNTRY:
case SearchModel::SEARCH_TYPE_COUNT:

View file

@ -115,6 +115,8 @@ string DebugPrint(SearchModel::SearchType type)
return "STREET";
case SearchModel::SEARCH_TYPE_CITY:
return "CITY";
case SearchModel::SEARCH_TYPE_VILLAGE:
return "VILLAGE";
case SearchModel::SEARCH_TYPE_STATE:
return "STATE";
case SearchModel::SEARCH_TYPE_COUNTRY: