我最近在我的应用程序上成功实现了 Algolia,就像 the examples .
但是初始搜索大约需要 5 到 7 秒,而且在检查了整个库代码和文档后,我无法找到使其更快的方法。经过初步搜索后,搜索变得非常快。
我的实现没有任何异常,但也许您可以看到一些我没有看到的东西。以下代码来 self 初始化 Algolia 的 Activity :
Searcher searcher = new Searcher(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY, ALGOLIA_INDEX_NAME);
searcher.setQuery(new Query("word").setExactOnSingleWordQuery(Query.ExactOnSingleWordQuery.ATTRIBUTE));
searcher.addNumericRefinement(new NumericRefinement("CountryId", NumericRefinement.OPERATOR_EQ, 1));
InstantSearch helper = new InstantSearch(this, searcher);
helper.setSearchOnEmptyString(false);
helper.search();
这是相关的 xml 布局:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="6dp"
android:paddingRight="10dp"
android:paddingLeft="1dp"
android:paddingTop="6dp">
<com.algolia.instantsearch.ui.views.SearchBox
android:id="@+id/searchBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:queryHint="@string/search_text_hint"
algolia:searchIcon="@drawable/icn_search_big"
algolia:closeIcon="@drawable/icn_clear_filled_big"
android:queryBackground="@drawable/sarch_query_shape"
android:background="@drawable/search_shape"
algolia:autofocus="true"
algolia:submitButtonEnabled="false" />
</FrameLayout>`
<com.algolia.instantsearch.ui.views.Hits
android:id="@+id/hits"
android:layout_width="match_parent"
android:layout_height="match_parent"
algolia:autoHideKeyboard="true"
algolia:hitsPerPage="6"
android:layout_below="@+id/searchBarParentLayout"
algolia:infiniteScroll="false"
algolia:itemLayout="@layout/search_item_algolia_row"/>
您知道这里的问题是什么吗?
最佳答案
很高兴当您切换到另一个 wifi 时问题消失了。
对于 future 可能遇到 Android InstantSearch 网络问题的读者:
- 首先,构建并运行one of our demo applications
- 如果运行示例应用程序没有问题,您可以尝试使用类似 Charles 的代理。调查您的应用和网络之间发生的事情
如果您在运行示例时问题仍然存在,或者您正在遵循 documentation , 发送电子邮件至 support@algolia.com
用您的代码示例描述问题!
关于android - Algolia Android 初始搜索真的很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44002365/