forked from organicmaps/organicmaps
[search] Improved the search speed for the cian project.
This commit is contained in:
parent
506ff4fca4
commit
193087b986
7 changed files with 70 additions and 12 deletions
|
@ -499,6 +499,15 @@ extern "C"
|
|||
});
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_search_SearchEngine_nativeCancelEverywhereSearch(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
GetPlatform().RunOnGuiThread([]()
|
||||
{
|
||||
g_framework->NativeFramework()->CancelSearch(search::Mode::Everywhere);
|
||||
});
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_com_mapswithme_maps_search_SearchEngine_nativeGetHotelTypes(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
|
|
|
@ -461,7 +461,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
args.putBoolean(DownloaderActivity.EXTRA_OPEN_DOWNLOADED, openDownloaded);
|
||||
if (mIsFragmentContainer)
|
||||
{
|
||||
SearchEngine.cancelSearch();
|
||||
SearchEngine.cancelInteractiveSearch();
|
||||
mSearchController.refreshToolbar();
|
||||
replaceFragment(MapManager.nativeIsLegacyMode() ? MigrationFragment.class : DownloaderFragment.class, args, null);
|
||||
}
|
||||
|
@ -1212,7 +1212,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
if (mSearchController.hide())
|
||||
{
|
||||
SearchEngine.cancelSearch();
|
||||
SearchEngine.cancelInteractiveSearch();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ class SearchWheel implements View.OnClickListener
|
|||
{
|
||||
mIsExpanded = false;
|
||||
mCurrentOption = null;
|
||||
SearchEngine.cancelSearch();
|
||||
SearchEngine.cancelInteractiveSearch();
|
||||
resetSearchButtonImage();
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ class SearchWheel implements View.OnClickListener
|
|||
Statistics.INSTANCE.trackRoutingEvent(ROUTING_SEARCH_CLICK, false);
|
||||
if (mCurrentOption != null || !TextUtils.isEmpty(SearchEngine.getQuery()))
|
||||
{
|
||||
SearchEngine.cancelSearch();
|
||||
SearchEngine.cancelInteractiveSearch();
|
||||
mCurrentOption = null;
|
||||
mIsExpanded = false;
|
||||
resetSearchButtonImage();
|
||||
|
|
|
@ -86,7 +86,7 @@ public class FloatingSearchToolbarController extends SearchToolbarController
|
|||
private void cancelSearchApiAndHide(boolean clearText)
|
||||
{
|
||||
SearchEngine.cancelApiCall();
|
||||
SearchEngine.cancelSearch();
|
||||
SearchEngine.cancelInteractiveSearch();
|
||||
|
||||
if (clearText)
|
||||
clear();
|
||||
|
|
|
@ -144,12 +144,18 @@ public enum SearchEngine implements NativeSearchListener,
|
|||
Framework.nativeClearApiPoints();
|
||||
}
|
||||
|
||||
public static void cancelSearch()
|
||||
public static void cancelInteractiveSearch()
|
||||
{
|
||||
sSavedQuery = "";
|
||||
nativeCancelInteractiveSearch();
|
||||
}
|
||||
|
||||
public static void cancelEverywhereSearch()
|
||||
{
|
||||
sSavedQuery = "";
|
||||
nativeCancelEverywhereSearch();
|
||||
}
|
||||
|
||||
public static void showResult(int index)
|
||||
{
|
||||
sSavedQuery = "";
|
||||
|
@ -183,6 +189,8 @@ public enum SearchEngine implements NativeSearchListener,
|
|||
|
||||
public static native void nativeCancelInteractiveSearch();
|
||||
|
||||
public static native void nativeCancelEverywhereSearch();
|
||||
|
||||
/**
|
||||
* @return all existing hotel types
|
||||
*/
|
||||
|
|
|
@ -43,7 +43,6 @@ import com.mapswithme.util.statistics.Statistics;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SearchFragment extends BaseMwmFragment
|
||||
implements OnBackPressListener,
|
||||
NativeSearchListener,
|
||||
|
@ -103,6 +102,9 @@ public class SearchFragment extends BaseMwmFragment
|
|||
return;
|
||||
}
|
||||
|
||||
if (mCianCategorySelected)
|
||||
return;
|
||||
|
||||
runSearch();
|
||||
}
|
||||
|
||||
|
@ -178,6 +180,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
|
||||
private final LastPosition mLastPosition = new LastPosition();
|
||||
private boolean mSearchRunning;
|
||||
private boolean mCianCategorySelected;
|
||||
private String mInitialQuery;
|
||||
@Nullable
|
||||
private String mInitialLocale;
|
||||
|
@ -274,9 +277,9 @@ public class SearchFragment extends BaseMwmFragment
|
|||
|
||||
private void updateResultsPlaceholder()
|
||||
{
|
||||
final boolean show = (!mSearchRunning &&
|
||||
mSearchAdapter.getItemCount() == 0 &&
|
||||
mToolbarController.hasQuery());
|
||||
final boolean show = !mSearchRunning
|
||||
&& mSearchAdapter.getItemCount() == 0
|
||||
&& mToolbarController.hasQuery();
|
||||
|
||||
UiUtils.showIf(show, mResultsPlaceholder);
|
||||
if (mFilterController != null)
|
||||
|
@ -531,7 +534,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
private void stopSearch()
|
||||
{
|
||||
SearchEngine.cancelApiCall();
|
||||
SearchEngine.cancelSearch();
|
||||
SearchEngine.cancelInteractiveSearch();
|
||||
onSearchEnd();
|
||||
}
|
||||
|
||||
|
@ -587,12 +590,19 @@ public class SearchFragment extends BaseMwmFragment
|
|||
@Override
|
||||
public void onCategorySelected(String category)
|
||||
{
|
||||
mToolbarController.setQuery(category);
|
||||
if (!TextUtils.isEmpty(category) && category.equals("cian "))
|
||||
{
|
||||
mCianCategorySelected = true;
|
||||
mToolbarController.setQuery(category);
|
||||
|
||||
Statistics.INSTANCE.trackSponsoredEvent(Statistics.EventName.SEARCH_SPONSOR_CATEGORY_SELECTED,
|
||||
Sponsored.TYPE_CIAN);
|
||||
showAllResultsOnMap();
|
||||
mCianCategorySelected = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mToolbarController.setQuery(category);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "base/logging.hpp"
|
||||
#include "base/macros.hpp"
|
||||
#include "base/pprof.hpp"
|
||||
#include "base/random.hpp"
|
||||
#include "base/scope_guard.hpp"
|
||||
#include "base/stl_add.hpp"
|
||||
#include "base/stl_helpers.hpp"
|
||||
|
@ -312,6 +313,30 @@ size_t OrderCountries(m2::RectD const & pivot, vector<shared_ptr<MwmInfo>> & inf
|
|||
auto const sep = stable_partition(infos.begin(), infos.end(), intersects);
|
||||
return distance(infos.begin(), sep);
|
||||
}
|
||||
|
||||
CBV DecimateCianResults(CBV const & cbv)
|
||||
{
|
||||
// With the typical amount of buildings in a relevant
|
||||
// mwm nearing 200000, the geocoding slows down considerably.
|
||||
// Leaving only a fraction of them does not seem
|
||||
// to worsen the percieved result.
|
||||
size_t const kMaxCianResults = 10000;
|
||||
static minstd_rand rng;
|
||||
auto survivedIds = base::RandomSample(cbv.PopCount(), kMaxCianResults, rng);
|
||||
sort(survivedIds.begin(), survivedIds.end());
|
||||
auto it = survivedIds.begin();
|
||||
vector<uint64_t> setBits;
|
||||
setBits.reserve(kMaxCianResults);
|
||||
size_t observed = 0;
|
||||
cbv.ForEach([&](uint64_t bit) {
|
||||
while (it != survivedIds.end() && *it < observed)
|
||||
++it;
|
||||
if (it != survivedIds.end() && *it == observed)
|
||||
setBits.push_back(bit);
|
||||
++observed;
|
||||
});
|
||||
return CBV(coding::CompressedBitVectorBuilder::FromBitPositions(move(setBits)));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// Geocoder::Geocoder ------------------------------------------------------------------------------
|
||||
|
@ -543,6 +568,9 @@ void Geocoder::InitBaseContext(BaseContext & ctx)
|
|||
ctx.m_features[i] = retrieval.RetrieveAddressFeatures(m_prefixTokenRequest);
|
||||
else
|
||||
ctx.m_features[i] = retrieval.RetrieveAddressFeatures(m_tokenRequests[i]);
|
||||
|
||||
if (m_params.m_cianMode)
|
||||
ctx.m_features[i] = DecimateCianResults(ctx.m_features[i]);
|
||||
}
|
||||
ctx.m_hotelsFilter = m_hotelsFilter.MakeScopedFilter(*m_context, m_params.m_hotelsFilter);
|
||||
}
|
||||
|
@ -1235,6 +1263,9 @@ void Geocoder::EmitResult(BaseContext const & ctx, City const & city, TokenRange
|
|||
|
||||
void Geocoder::MatchUnclassified(BaseContext & ctx, size_t curToken)
|
||||
{
|
||||
if (m_params.m_cianMode)
|
||||
return;
|
||||
|
||||
ASSERT(ctx.m_layers.empty(), ());
|
||||
|
||||
// We need to match all unused tokens to UNCLASSIFIED features,
|
||||
|
|
Loading…
Add table
Reference in a new issue