处理搜索的最佳做法 [英] Best Practices for Handling Search

查看:113
本文介绍了处理搜索的最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SearchView设置,并且使用RetrofitOtto具有松散的解耦架构.

I've got a SearchView setup, and I have a loosely decoupled architecture using Retrofit and Otto.

我想知道最佳做法适用于Android或一般的任何移动应用程序中的搜索(意味着类似的内容也可以应用于iOS).

I am wondering what the Best Practices are for Search in Android, or any mobile application in general (meaning something like this could be applied to iOS as well).

具体地说,我正在使用AutoCompleteTextView来处理SearchView中的建议,并且数据直接来自API.我不认为这是最佳做法,因为每次用户更改SearchView中的文本时,都会启动API调用.

Specifically I am using an AutoCompleteTextView to handle suggestions in my SearchView and the data is coming straight from the API. I don't believe this is a best practice since everytime a user changes text in the SearchView there is an API call initiated.

我正在考虑在SQLite中存储一个缓存,然后从那里ping结果,但是如果用户想要最即时的数据怎么办?您将如何处理?那会采用什么模式?

I'm thinking about storing a Cache in SQLite and then pinging results from there, but what if the user wants the most immediate data? How would you handle that? What pattern would that employ?

感谢您对Android最佳搜索架构或方法的任何想法.

Would appreciate any thoughts on the best architecture or approach to Search in Android.

推荐答案

所以要以足够的方式回答这个问题,因为我对其他答案不满意,因此还需要考虑一些其他步骤.

So to answer this question in a sufficient way, as I was not satisfied with the other answers here there are a few more steps to consider in this problem.

首先,我们需要问一些有关如何解决此问题的问题:

First we would need to ask a few questions in regards to how we would tackle this issue:

  • 是否有自动完成功能?
  • 搜索范围是什么?
  • 会缓存吗?

还有更多问题.

我可能会首先构建一个自定义适配器来处理搜索中的查询,然后对用户的查询实施主动缓存.从用户查询非常重要的意义上来说,这很重要.仅对Autocomplete使用缓存的结果可能是有道理的,实现自动完成并在每次文本更改时对服务器执行ping操作非常昂贵.

I would probably first build a custom adapter to handle the querying in the search, then implement aggressive caching on the user's queries. This is important in the sense that a user's queries are very important. It would probably make sense to only used cached results for Autocomplete it is very expensive to implement autocomplete and have it ping the server at every text change.

可以通过使用Android中的SQLite帮助器来完成缓存.这可能会很昂贵,但是我们正在处理简单的查询对象(因为从API中应该是这种情况,对象应该在内存或字节大小上都很昂贵).

Caching can be accomplished by using the SQLite helpers in Android. This can be expensive, but we are dealing with simple query objects, (as this should be the case from the API the objects should be memory or byte size expensive).

这篇关于处理搜索的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆