2

I've been looking at different ways to implement an instant text search on my web application; at the moment it uses a very basic SQL LIKE query with wildcards.

I have looked at many ways to implement searches, but I never saw anyone suggest to do the following:

  1. As the user types, when the query gets to 4 or 5 characters, perform the database search.

  2. Display the results to the user, and as they continue typing, just use Javascript to filter the results, so no more database calls are required.

This way there would only ever be one database call per search, if the user makes a typo, they can backspace and Javascript would take care of displaying the correct results.

Are there any downsides to this method?

2
  • you can use jquery autocomplete! Commented Mar 11, 2013 at 9:22
  • 1
    With many systems where you might want to do this, 4~5 characters would still result in a large number of possible rows. However on some systems it could be useful. Personally I have searched when each character is entered, but used a timer before the search so the AJAX call only occurs if the user has stopped typing (half a second will suffice). Commented Mar 11, 2013 at 9:39

1 Answer 1

1

This seems to work in theory, but I personally prefer either pressing enter or waiting 500 milliseconds of inactivity before searching.

One thing that may cause an extra DB query is if the user backspaces at your given interval (4 characters in your case).

But I suppose the real downside would be extra JS coding + still needing the PHP coding.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, I'll give the 500 millisecond & Javascript filter methods a go, and see which I prefer. Thanks for your answer :)
You are very welcome, and I know I learned something from you today if I ever need to optimize for that last bit of performance. It doesn't even look like Google's doing that although some caching seems to be in effect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.