Apparent problem with default search

OJS, PHP 7.2.30, Apache2 2.4.25 (Debian), PostgreSQL 9.6.19

We are using the default search engine with pdftotext. All our papers are in PDF.

After an author noticed that their paper was not being found by the search, I rebuilt the index using “php tools/rebuildSearchIndex.php”. This produced a large (>100) number of messages like this:

PHP Notice:  Array to string conversion in
   OJSHOME/lib/pkp/classes/search/ on line 37

That line is in function filterKeywords():

if (is_array($text)) $text = join("\n", $text);

That PHP code does not produce the message when $text is an array of strings, but it does if an element of $text is also an array. For example:

$text = array('aaa',array('bbb','ccc'));
$text = join("\n",$text);

will give the message and the result is the string “aaa\nArray”. (“Array” is the result of converting an array to a string.) As a check that this was happening, after the indexing finished, the search “Array” gives some hits that appear to not contain the word “Array” (or “array” or plurals).

I don’t understand it enough to know why $text could be an array with an array element, but if the default string “Array” is appearing in the index it is likely that something else is missing.

A fix of the symptom is to look at the entries of the array:

if (is_array($text)) {
   $textLen = count($text);
   for ($i = 0; $i < $textLen; ++$i)
      if (is_array($text[$i]))
         $text[$i] = join("\n",$text[$i]);
   $text = join("\n",$text);

But I don’t know if that fixes the real problem.

Thanks, Brendan.

Hi @bdm,

I’m fairly sure this is resolved in OJS 3.2.x already; if upgrading is an option, I’d recommend that before debugging in much depth.

Alec Smecher
Public Knowledge Project Team

Bumping this thread. We are seeing the same issue with OJS 3.2.1-2 when using “php tools/rebuildSearchIndex.php”

PHP Notice: Array to string conversion in /lib/pkp/classes/search/ on line 37

Richard Higgins
Indiana University Libraries