forked from organicmaps/organicmaps
[search] [bookmarks] Added a method to reset the bookmarks engine.
This commit is contained in:
parent
63257ea2f4
commit
2aea4ca36c
10 changed files with 48 additions and 0 deletions
|
@ -202,5 +202,8 @@ UNIT_CLASS_TEST(SearchAPITest, BookmarksSearch)
|
|||
m_api.OnBookmarksAttached(groupInfos);
|
||||
}
|
||||
runTest(query, kml::MarkGroupId(11), vector<kml::MarkId>({2, 1}));
|
||||
|
||||
m_api.ResetBookmarksEngine();
|
||||
runTest(query, kml::MarkGroupId(11), {});
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -423,6 +423,12 @@ unordered_set<kml::MarkGroupId> const & SearchAPI::GetIndexableGroups() const
|
|||
return m_indexableGroups;
|
||||
}
|
||||
|
||||
void SearchAPI::ResetBookmarksEngine()
|
||||
{
|
||||
m_indexableGroups.clear();
|
||||
m_engine.ResetBookmarks();
|
||||
}
|
||||
|
||||
void SearchAPI::OnBookmarksCreated(vector<BookmarkInfo> const & marks)
|
||||
{
|
||||
vector<BookmarkIdDoc> data;
|
||||
|
|
|
@ -161,6 +161,13 @@ public:
|
|||
bool IsIndexingOfBookmarkGroupEnabled(kml::MarkGroupId const & groupId);
|
||||
std::unordered_set<kml::MarkGroupId> const & GetIndexableGroups() const;
|
||||
|
||||
// Returns the bookmarks search to its default, pre-launch state.
|
||||
// This includes dropping all bookmark data for created bookmarks (efficiently
|
||||
// calling OnBookmarksDeleted with all known bookmarks as an argument),
|
||||
// clearing the bookmark search index, and resetting all parameters to
|
||||
// their default values.
|
||||
void ResetBookmarksEngine();
|
||||
|
||||
void OnBookmarksCreated(std::vector<BookmarkInfo> const & marks);
|
||||
void OnBookmarksUpdated(std::vector<BookmarkInfo> const & marks);
|
||||
void OnBookmarksDeleted(std::vector<kml::MarkId> const & marks);
|
||||
|
|
|
@ -78,6 +78,16 @@ Processor::Processor(Emitter & emitter, base::Cancellable const & cancellable)
|
|||
{
|
||||
}
|
||||
|
||||
void Processor::Reset()
|
||||
{
|
||||
m_index = {};
|
||||
m_docs.clear();
|
||||
m_indexDescriptions = false;
|
||||
m_indexableGroups.clear();
|
||||
m_idToGroup.clear();
|
||||
m_bookmarksInGroup.clear();
|
||||
}
|
||||
|
||||
void Processor::EnableIndexingOfDescriptions(bool enable) { m_indexDescriptions = enable; }
|
||||
|
||||
void Processor::EnableIndexingOfBookmarkGroup(GroupId const & groupId, bool enable)
|
||||
|
|
|
@ -43,6 +43,8 @@ public:
|
|||
Processor(Emitter & emitter, base::Cancellable const & cancellable);
|
||||
~Processor() override = default;
|
||||
|
||||
void Reset();
|
||||
|
||||
// By default, only bookmark names are indexed. This method
|
||||
// should be used to enable or disable indexing bookmarks
|
||||
// by their descriptions.
|
||||
|
|
|
@ -172,6 +172,13 @@ void Engine::EnableIndexingOfBookmarkGroup(bookmarks::GroupId const & groupId, b
|
|||
});
|
||||
}
|
||||
|
||||
void Engine::ResetBookmarks()
|
||||
{
|
||||
PostMessage(Message::TYPE_BROADCAST, [](Processor & processor) {
|
||||
processor.ResetBookmarks();
|
||||
});
|
||||
}
|
||||
|
||||
void Engine::OnBookmarksCreated(vector<pair<bookmarks::Id, bookmarks::Doc>> const & marks)
|
||||
{
|
||||
PostMessage(Message::TYPE_BROADCAST,
|
||||
|
|
|
@ -111,6 +111,9 @@ public:
|
|||
void EnableIndexingOfBookmarksDescriptions(bool enable);
|
||||
void EnableIndexingOfBookmarkGroup(bookmarks::GroupId const & groupId, bool enable);
|
||||
|
||||
// Clears all bookmarks data and caches for all processors.
|
||||
void ResetBookmarks();
|
||||
|
||||
void OnBookmarksCreated(std::vector<std::pair<bookmarks::Id, bookmarks::Doc>> const & marks);
|
||||
void OnBookmarksUpdated(std::vector<std::pair<bookmarks::Id, bookmarks::Doc>> const & marks);
|
||||
void OnBookmarksDeleted(std::vector<bookmarks::Id> const & marks);
|
||||
|
|
|
@ -334,6 +334,11 @@ void Processor::EnableIndexingOfBookmarkGroup(bookmarks::GroupId const & groupId
|
|||
m_bookmarksProcessor.EnableIndexingOfBookmarkGroup(groupId, enable);
|
||||
}
|
||||
|
||||
void Processor::ResetBookmarks()
|
||||
{
|
||||
m_bookmarksProcessor.Reset();
|
||||
}
|
||||
|
||||
void Processor::OnBookmarksCreated(vector<pair<bookmarks::Id, bookmarks::Doc>> const & marks)
|
||||
{
|
||||
for (auto const & idDoc : marks)
|
||||
|
|
|
@ -97,6 +97,8 @@ public:
|
|||
void EnableIndexingOfBookmarksDescriptions(bool enable);
|
||||
void EnableIndexingOfBookmarkGroup(bookmarks::GroupId const & groupId, bool enable);
|
||||
|
||||
void ResetBookmarks();
|
||||
|
||||
void OnBookmarksCreated(std::vector<std::pair<bookmarks::Id, bookmarks::Doc>> const & marks);
|
||||
void OnBookmarksUpdated(std::vector<std::pair<bookmarks::Id, bookmarks::Doc>> const & marks);
|
||||
void OnBookmarksDeleted(std::vector<bookmarks::Id> const & marks);
|
||||
|
|
|
@ -132,6 +132,9 @@ UNIT_CLASS_TEST(BookmarksProcessorTest, Smoke)
|
|||
"N Hotel" /* customName */,
|
||||
"Clean establishment with a reasonable price" /* description */));
|
||||
TEST_EQUAL(Search("place", GroupId{0}), Ids({18}), ());
|
||||
|
||||
GetProcessor().Reset();
|
||||
TEST_EQUAL(Search("place", GroupId{0}), Ids{}, ());
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(BookmarksProcessorTest, IndexDescriptions)
|
||||
|
|
Loading…
Add table
Reference in a new issue