algolia / scout-extended

Scout Extended: The Full Power of Algolia in Laravel
https://www.algolia.com/doc/framework-integration/laravel/getting-started/introduction-to-scout-extended/
MIT License
400 stars 87 forks source link

Appeding Model Path on generating ID from scoutKey with Modle #209

Open MadaniTech opened 5 years ago

MadaniTech commented 5 years ago

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.

nunomaduro commented 5 years ago

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

MadaniTech commented 5 years ago

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.

nunomaduro commented 5 years ago

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

MadaniTech commented 5 years ago

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

tao commented 1 year ago

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,
        ];
    }
LoganTFox commented 5 months ago

+1