When searching with ajax based suggesting field, how many letters should be typed before it starts to suggest results? 1,2,3..
2 Answers
Secondary rank
If you have another factor that can rank the results (e.g. "popularity", "kuakeli rank"):
- start with the first letter
- limit results by second rank, by picking the TOP N
(roughly: SELECT TOP 10 FROM Stuff WHERE Name LIKE "x*" ORDER BY Rank
)
If you don't have that rank, you could still start after the first letter, but results aren't as useful. Still, there's no usability reason to start with a sorted list:
SELECT TOP 10 FROM Stuff WHERE Name LIKE "x*" ORDER BY Name
Performance reasons
Thee are a few traditional reasons for delaying the query:
- Part of your query runs synchronous, and you have to limit UI blocking
- You have to limit traffic / hits to the search provider
This is typically achieved by starting search if no key was pressed for the last few hundred milliseconds, or starting only after a minimum string length.
There's one case left (that I can think of) where starting after the N th key might improve usability: Misleading matches. If your search pool contains elements like this:
SDBXXFDR 1722 Lengthy
SDBXXFDR 1723 Still Lengthy
...
SDBXXFDR 1799 Short
SOBXXFDR 1972 Lengthy with ripples
And you just type "S", the "SD" results may hide the SO one, the chance of pickign the wrong one is rather high. However, that sems very constructed, and I'm not sure if incremental search is a good solution at all if this would be a problem.
-
4Great answer, I just want to add that performance issues can be solved by delaying search for about 0.5 sec after keypress, so if user is typing smth, intermediate request will not be sent to server until he stops typing. Commented Mar 8, 2011 at 13:12
-
1@Nikita - thanks, I actually edited that out before the initial submit. I've added it again :) Commented Mar 8, 2011 at 16:32
-
1Really good, thank you. How about getting the results. Should the search look inside words or just the beginning of the word. fx. if search phrase is "sic" should it result fx. "basic" or just words beginning with "sic"?– kuakeliCommented Mar 9, 2011 at 7:07
-
My recent conclusions: How well they match could be (or go into) the secondary rank - e.g. just list the "starts with sic" results first, then those just containing sic. Commented Mar 9, 2011 at 8:09
An autocomplete functionality is most optimally backed by a structure called a Trie.
Using a trie, you would'nt even have to set a lower limit on characters. Lookup is performed in O(n) where n is length of the query text and is independent (mostly) of the number of search items that are in your database.
Please take a look at a node.js based trie implementation that I did - MyTriePOC.
From a user experience perspective, if you are really setting a lower limit, best practice is to provide a tooltip to instruct the user to keep typing more characters for best results.