scout-extended icon indicating copy to clipboard operation
scout-extended copied to clipboard

Appeding Model Path on generating ID from scoutKey with Modle

Open MadaniTech opened this issue 6 years ago • 6 comments

Scout Extended is wonderful with its latest features to use Algolia Search API in laravel. But It has a bad approach to save value of Model path with ScoutKey.

On encryption it is using following in ObjectIdEncrypter:

`public static function encrypt($searchable, int $part = null): string { $scoutKey = method_exists($searchable, 'getScoutKey') ? $searchable->getScoutKey() : $searchable->getKey(); $meta = [get_class($searchable->getModel()), $scoutKey];

if ($part !== null) { $meta[] = $part; } return implode(self::$separator, $meta); }`

Because of this ObjectID is importing like this: objectID: {ModelPath}::ScoutKey on importing and searching results also show a string including Model Path. Any body can help in this matter.

MadaniTech avatar Nov 03 '19 15:11 MadaniTech

Hey @MadaniTech, what issues are caused in your side about having the model path on the objectID?

nunomaduro avatar Nov 04 '19 10:11 nunomaduro

Thanks for the response @nunomaduro. Is this right to show the path on response while fetching the results from search query? I am writing my logics which also impact on directory path and on the fly I am showing this path as objectID in response.

MadaniTech avatar Nov 04 '19 19:11 MadaniTech

Yeah - at the moment, moving the model from directory will force you to reimport all records. Maybe we can improve this in the future.

nunomaduro avatar Nov 04 '19 20:11 nunomaduro

Can I modify it for the time for my project? In case please help me out. Thanks @nunomaduro.

MadaniTech avatar Nov 05 '19 05:11 MadaniTech

I would also like to override the objectID because saving the entire model path makes no sense if I'm searching from the javascript frontend. I would like the objectIDs to be customised so they can just be Article::1 or Company::5 instead of App\Models\Company::5.

Laravel has a class_basename function to get the model name but there's is no method to customize the objectID and I can't override it in the toSearchableArray method either.

    public function toSearchableArray()
    {
        return [
            'objectID' => class_basename($this) . '::' . $this->id,
            'name' => $this->name,
            'description' => $this-> description,
        ];
    }

tao avatar Nov 24 '22 10:11 tao