【问题标题】:Algolia Android initial search is really slowAlgolia Android初始搜索真的很慢
【发布时间】:2017-05-16 13:07:02
【问题描述】:

我最近在我的应用上成功实现了 Algolia,就像 the examples 一样。

但最初的搜索大约需要 5 到 7 秒,在检查了整个库代码和文档后,我找不到让它更快的方法。初始搜索后,搜索变得非常快。

在我的实现中没有什么不寻常的地方,但也许你能看到一些我没有看到的东西。以下代码来自我初始化 Algolia 的活动:

    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"/>

你知道这里有什么问题吗?

【问题讨论】:

  • 有趣..如果您删除helper.setSearchOnEmptyString(false);,或者将其设置为true,您还有同样的问题吗?另外,我很好奇是网络调用需要 5 秒,还是因为我们最初发送网络调用时延迟了 5 秒(出于某种奇怪的原因)。如果你有Charles之类的工具,可以快速检查问题是否出在网络端(以及Algolia的后端)。
  • 谢谢你的回答。问题似乎与wifi连接有关。使用网络工具签入后,我看到第一个请求延迟了 5 秒。然后我切换到另一个wifi,问题消失了。可能是因为 vpn。
  • 很高兴听到您找到了解决方案!我希望您喜欢 Android 版 InstantSearch :)
  • 我们对 Algolia 的速度非常满意。但是我们很难使用 algolia 客户端。您必须更新您的示例和文档。由于文档很旧,我们深入研究代码以了解如何与 algolia 集成。无论如何,它很好,现在正在工作。再次感谢。
  • 感谢您的建设性反馈!事实上,我们目前正在努力更新我们的示例和文档,以使开发人员更容易集成。现在是当务之急。敬请期待:)

标签: android search algolia


【解决方案1】:

很高兴您切换到另一个 wifi 后问题消失了。

对于可能会遇到 InstantSearch Android 网络问题的未来读者:

  • 首先,构建并运行one of our demo applications
  • 如果您发现运行示例应用程序没有问题,您可以尝试使用像 Charles 这样的代理来调查您的应用程序和网络之间发生的情况

如果您在运行示例时问题仍然存在,或者如果您正在关注documentation,请发送电子邮件至support@algolia.com,使用您的代码示例描述问题!

【讨论】:

    猜你喜欢
    • 2016-05-27
    • 1970-01-01
    • 2013-06-24
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多