Live Search

From: Date: Fri, 27 Nov 2009 18:47:12 +0000
Subject: Live Search
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-6624@lists.php.net to get a copy of this message
Hi Hannes and Philip, I've done some work on the back-end for a live, search-as-you-type, feature. I have written a more specialized version of manual-lookup.php that I have tentatively called search-api.php. This script differs from manual-lookup in that it produces JSON output and has been tweaked to run a bit faster. I have also tuned the 'scoring' logic to (hopefully) produce more relevant results. On my machine it completes in 30ms vs. 112ms for manual-lookup.php. On a real-world PHP mirror, it will run slower. Testing this morning, my nearest mirror (ca.php.net) takes 337ms for a manual-lookup.php request. This is about 3 times slower, so we might expect that search-api.php will take around 90ms in the real-world. LOCAL: $ ab -n10 http://php-net/search-api.php?query=sub ... Time per request: 30.415 [ms] (mean) $ ab -n10 http://php-net/manual-lookup.php?pattern=sub ... Time per request: 112.200 [ms] (mean) CA.PHP.NET $ ab -n10 http://ca.php.net/manual-lookup.php?pattern=sub ... Time per request: 337.357 [ms] (mean) The main speed-up of search-api comes from a function index that it builds on the first run and caches for subsequent requests. Without the cache, it is only slightly faster than manual-lookup.php. I believe that we could further optimize it by removing some of the includes at the top of the file and doing some profiling, but I am not sure that this is necessary as a ~100ms response time should be sufficient for live-search. One shortcoming of 'search-api.php' is that it does not perform an exhaustive search of the manual or php website. It appears that (at present) a full-text search would be too slow for the live-search feature. One possible work-around is to make two requests to populate the live-search results. One query against the function index and a second, more exhaustive, query against the entire manual and/or website. The function search results would come in quickly, and then the deep search results would come in after and could be merged with or appended to the existing results. That being said, I am not sure that a deep/full-text search is required for the live search feature. We could always add such a feature later. I would like to hear what you both think of how this is progressing. Any gotchas? Let me know if you would like to see the search-api.php source. If I am on the right track, I can move on to the front-end. Regards, Stew

« previous php.webmaster (#6624) next »