[php-blog-cvs] r2483 - in trunk: docs include
A reliable, secure & extensible PHP blog | Not mainstream since 2002
Brought to you by:
garvinhicking,
jhermanns
From: garvinhicking at B. <gar...@ma...> - 2009-03-04 12:10:44
|
Author: garvinhicking Date: 2009-03-04 13:10:29 +0100 (Wed, 04 Mar 2009) New Revision: 2483 Modified: trunk/docs/NEWS trunk/include/functions_entries.inc.php Log: Patch by onli to improve quicksearch Modified: trunk/docs/NEWS =================================================================== --- trunk/docs/NEWS 2009-02-26 10:30:20 UTC (rev 2482) +++ trunk/docs/NEWS 2009-03-04 12:10:29 UTC (rev 2483) @@ -3,6 +3,9 @@ Version 1.5 () ------------------------------------------------------------------------ + * Enhance quicksearch by performing a wildcard-search for the + searchterms, when less than 4 matches are found. (onli) + * Updated czech translation, by Vlada Ajgl * Use a space instead of comma to seperate DENY rules in spamblock Modified: trunk/include/functions_entries.inc.php =================================================================== --- trunk/include/functions_entries.inc.php 2009-02-26 10:30:20 UTC (rev 2482) +++ trunk/include/functions_entries.inc.php 2009-03-04 12:10:29 UTC (rev 2483) @@ -722,11 +722,13 @@ * @access public * @param string The searchterm (may contain wildcards) * @param int Restrict the number of results [also uses $serendipity['GET']['page'] for pagination] + * @param array Add search Results at the top * @return array Returns the superarray of entries found */ -function &serendipity_searchEntries($term, $limit = '') { +function &serendipity_searchEntries($term, $limit = '', $searchresults = '') { global $serendipity; + $orig_limit = $limit; if ($limit == '') { $limit = $serendipity['fetchLimit']; } @@ -817,10 +819,35 @@ $search =& serendipity_db_query($querystring); - if (is_array($search)) { + //Add param searchresults at the top and remove duplicates. + if (is_array($searchresults)) { + $ids_current = array(); + foreach($searchresults AS $idx => $data) { + $ids_current[$data['id']] = true; + } + + foreach($search AS $idx => $data) { + if (isset($ids_current[$data['id']])) { + unset($search[$idx]); + } + } + $search = array_merge($searchresults, $search); + } + + //if * wasn't already appended and if there are none or not enough + //results, search again for entries containing the searchterm as a part + if (strpos($term, '*') === false) { + if (! is_array($search)) { + return serendipity_searchEntries($term.'*', $orig_limit); + }else if (count($search) < 4){ + return serendipity_searchEntries($term.'*', $orig_limit, $search); + } + } + + if (is_array($search)){ serendipity_fetchEntryData($search); } - + return $search; } @@ -1644,4 +1671,4 @@ AND n.categoryid = " . (int)$id . " ORDER BY n.category_left DESC, p.category_left ASC"); return $r; -} \ No newline at end of file +} |