teamtnt / laravel-scout-tntsearch-driver

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch
MIT License
1.1k stars 144 forks source link

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

Closed vezlius closed 3 months ago

vezlius commented 6 years ago

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: mbstrtolower() 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?

rorymcdaniel commented 6 years ago

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

khuesmann commented 6 years ago

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

novocent commented 6 years ago

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

hackerESQ commented 6 years ago

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| }
bcorcoran commented 6 years ago

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().