Live Search in Django

Viewed 4376

I am working on a Django application that requires the implementation of live search i.e. filtering and displaying the search result every time the form input is changed.

For example:

Consider I wanted to search my database for books when a book "name" is provided. Now, I want to suggest books which has a "name" similar to the "name" provided as input.

And, I want these suggestions to be live - every time the input field for "name" is changed, my application should provide new and more accurate suggestions.

How should I go about doing that?

I have two solutions in mind.

Solution - 1

Use jQuery and do AJAX calls to fetch new suggestions, every time the content of the input field for "name" is changed.

Solution - 2

Fetch all the books available in the database and store it in a JS array and then use this array to provide suggestions.




I think solution - 2 would not be feasible for large databases as we will not able to create arrays of such large sizes.

So, solution - 1 is the only option left for large databases.

Or are there any other ways to implement this "live search" option ?

If yes, then what are they?

else, what are the ways in which I can optimize solution - 1 ?

Thanks!

1 Answers
Related