1

Possible Duplicate:
How to detect a pause in input for UISearchBar/UITextField?

I have a UISearchDisplayController. Currently I am sending a string to my webserver and it returns back with an array of results. I want to be able to "search as I type".

What is the recommended way of doing this? Should I hit the server character by character and return results? That seems expensive.

EDIT:

Each character returns a full set of results. Not just a single result.

Community
  • 1
  • 1
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
  • This question should help get you on the right track. Hit the server after a second or so of pause from the user (probably how google, etc work) http://stackoverflow.com/questions/7061377/how-to-detect-a-pause-in-input-for-uisearchbar-uitextfield/ – smdvlpr Aug 15 '11 at 03:52

4 Answers4

0

This is pretty much how most applications do it.

The best way to answer your concerns about performance is to do some benchmarking. You can make adjustments, e.g. don't start searching until they've entered at least 3 letters, only check every 2 letters, and so forth. Depending on the data you're dealing with, caching could also be an option. Or maybe it'll make more sense to pull down the full data set prior to doing the search if the data is small enough and do the filtering on the device.

csano
  • 13,266
  • 2
  • 28
  • 45
0

It's expensive. But that's just about the only way. If you're interested in lowering the cost, try (1) caching, (2) adding a small delay between the keystroke and the request, and (3) fetching relevant client-side data first, such as "recents", "favorites", and so on.

john
  • 3,043
  • 5
  • 27
  • 48
0

Can you afford to have the server return an entire list of all of the results with the first character? If not, you're going to have to hit the server over-and-over. It'll help a little if you hit the server and you reach a point where you can afford to return the rest of the list, return it and let the application handle the rest.

David McGraw
  • 5,157
  • 7
  • 36
  • 36
  • The server returns a full list of results per character. Any recommendations? – Sheehan Alam Aug 15 '11 at 02:29
  • If you get all of the results, store it, and begin searching it instead of the server. This, obviously, requires you to re-write the search routine. If you don't have the time to do that then stick with hitting the server until it appears that it's no longer feasible. – David McGraw Aug 15 '11 at 02:55
0

Of course it's too expensive . Download the whole list to client... Then search the list.

Sven Tan
  • 1,062
  • 7
  • 15
  • 1
    That's not very practical when the "list" gets really, super large. A good search implementation would return the "top" results for that query, and so when searching 'A' you wouldn't want to list all 10,000+ responses that begin with the letter 'A', you'll just return say, 20. That way, as the user adds more letters to his query, the search results are narrowed, and a huge burden isn't placed on the server and/or client by sending the entire "list" every time a query is performed. – john Aug 15 '11 at 04:43