问题
I want to add a spotlight search functionality - search results being displayed with rich contents like thumbnail etc in a drop down menu changing on each keyup event - just like the apple.com search - to a site, having data in MySQL InnoDB tables. So basically that is displaying search results based on the part of the query that has already been input (so not autocomplete).
The data is spread into separate tables for categories, help pages, blog pages and so on. The search script must take into account just a subset of columns.
Since it seems to be a popular demand, I guess there are some PHP search engine projects (preferably open-source and with memcached support), which could be integrated into the existing system on the basis of regular exports of relevant data from the working db/tables.
Are there any solutions out there? Which one would you recommend? Or maybe it would be better to implement it the other way around?
Thanks
回答1:
This would be a job for AJAX. Check out JQuery's implementation of it at: http://api.jquery.com/category/ajax/
Create a PHP script that displays your results as if someone typed them and clicked a button to 'search'. Then, use an ajax call to that scripts and replace the innerHTML of a (or appropriate HTML tag)
Something like this:
hello.php
<?php echo "Hello World"; ?>
index.html
<html>
<head>
<script language="javascript">
function update_results(){
$.ajax({
url: 'hello.php',
success: function(data) {
$('#results').html(data);
}
});
}
</script>
</head>
<body>
<label>Spotlight: <input id="q" type="text" onkeypress="update_results()" /></label>
<div id="results"></div>
</body>
</html>
Where hello.php is the page you setup with your pretty results.
回答2:
That’s exactly what DBruns gave you, above. The job of programming a complex system like that is to create your own hello.php which provides those search results using an adaptive query which can work across multiple tables.
来源:https://stackoverflow.com/questions/2858815/spotlight-search-with-php