Skip to content

Commit 6332782

Browse files
committed
search: Fix incorrect result count in opensearch suggestions
The descriptions displayed under the OpenSearch suggestions in a web browser always said "1 result". This also emitted a warning on the server-side: > PHP Warning: array_key_exists(): The first argument should be > either a string or an integer) Ref #10017.
1 parent bc42dee commit 6332782

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

templates/html/search_functions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ function report_results(&$docs)
301301
echo "</div>\n";
302302
}
303303

304+
/**
305+
* @param string $query
306+
* @return array[] List of matched documents, with each array value
307+
* in the shape:
308+
* - string url
309+
* - string name
310+
* - float rank
311+
* - array[] words List of word arrays, each word array
312+
* holding properties "word" (string), "match" (string) and "freq" (int)
313+
*/
304314
function run_query($query)
305315
{
306316
if(strcmp('4.1.0', phpversion()) > 0)

templates/html/search_opensearch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function opensearch_xml_results($query, array $results)
6161
{
6262
foreach ($val['words'] as $j => $word)
6363
{
64-
if (array_key_exists($word, $qs_results))
64+
if (array_key_exists($word['word'], $qs_results))
6565
$qs_results[$word['match']]++;
6666
else
6767
$qs_results[$word['match']] = 1;
@@ -96,7 +96,7 @@ function opensearch_json_results($query, array $results)
9696
{
9797
foreach ($val['words'] as $j => $word)
9898
{
99-
if (array_key_exists($word, $qs_results))
99+
if (array_key_exists($word['word'], $qs_results))
100100
$qs_results[$word['match']]++;
101101
else
102102
$qs_results[$word['match']] = 1;

0 commit comments

Comments
 (0)