laravel-scout-tntsearch-driver icon indicating copy to clipboard operation
laravel-scout-tntsearch-driver copied to clipboard

Doesn't append a new value or getting an error in toSearchableArray method

Open vezlius opened this issue 7 years ago • 5 comments

If I want to load relationship tasks in a parent's model toSearchableArray() method

public function toSearchableArray()
{
    $this->tasks;
    return $this->toArray();
}

I get this error: ErrorException: mb_strtolower() expects parameter 1 to be string, array given

or, if I want to adjust array in the same method...

public function toSearchableArray()
{
    $array = $this->toArray();
    $array['test'] = 'Test string';
    return $array;
}

...it doesn't append new value. It's like nothing ever happened.

Everything works as intended when I try different search driver. Any ideas?

vezlius avatar Aug 04 '18 16:08 vezlius

I'm seeing the same thing. toSearchableArray doesn't appear to have any impact on the search results

rorymcdaniel avatar Aug 14 '18 10:08 rorymcdaniel

same for me ... toSearchableArray has no impact on search results

edit: i had to use scout:import App\Model instead of tntsearch:import App\Model

khuesmann avatar Aug 15 '18 15:08 khuesmann

I think I have the same issue. I can manually build the index using createIndex(), but updates and edits to the model are ignored.

novocent avatar Aug 28 '18 16:08 novocent

Here's the full exception


   ErrorException  : mb_strtolower() expects parameter 1 to be string, array given

  at /Users/XXX/Dropbox/laravel/XXX/vendor/teamtnt/tntsearch/src/Support/Tokenizer.php:8
     4| class Tokenizer implements TokenizerInterface
     5| {
     6|     public function tokenize($text, $stopwords = [])
     7|     {
  >  8|         $text  = mb_strtolower($text);
     9|         $split = preg_split("/[^\p{L}\p{N}]+/u", $text, -1, PREG_SPLIT_NO_EMPTY);
    10|         return array_diff($split, $stopwords);
    11|     }
    12| }


hackeresq avatar Sep 21 '18 21:09 hackeresq

This happens when you reference an eloquent relationship, e.g. if you were indexing a Post that hasOne->(Author), and you're trying return $this->author->name (as an example) within a toSearchableArray().

bcorcoran avatar Oct 24 '18 21:10 bcorcoran