instant search for website

5.4k Views Asked by At

I need to arrange instant search for my website (like google instant). When the user is typing, the script should suggest results. As I understood I need php+html+javascript. Any suggestions, or link or something helpfull?

thanks in advance

4

There are 4 best solutions below

0
On

Try it with jQuery UI Autocomplete. It's easy to setup and fairly easy to implement what you're after:

http://jqueryui.com/demos/autocomplete/

The data for the search will be in an array of strings, like

[ "tag1", "tag2", "tag3" ... ]

so you'll need to do a database query (or setup manual search terms) and populate your array based on that.

0
On

You should set tags for each article, or ex. search in every category on your site.

Example code for the front-end:

        // index.html

        // ajax
        <script type="text/javascript">  
            function loadXML(query) {
                $.ajax({  
                    type: "POST",  
                    data: ({ajaxSearch : query.value}),  
                    url: 'search.php',
                    success: function(data) {  
                        $('#searchcontainer').html(data);  
                    }  
                }); 
        </script>

        // html
        <input type="text" id="ajaxSearch" onkeyup="loadXML(this);" />
        <div id="searchcontainer"></div>
3
On

This is usually done using AJAX. http://www.w3schools.com/php/php_ajax_livesearch.asp

0
On

In order to do that you need crazy amount of indexing. You need to index almost every keyword and store search results for each keyword. There is no way you can do a live search on database that fast. Once you have good index you can use .keypress function of JQuery to detect if user is typing something, once user types something you can send the search query to the server and fetch the result and display using javascript.