Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MadaniTech opened this issue Nov 3, 2019 · 6 comments
Open

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

MadaniTech opened this issue Nov 3, 2019 · 6 comments

Comments

@MadaniTech
Copy link

MadaniTech commented Nov 3, 2019

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
Copy link
Contributor

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

@MadaniTech
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

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

@tao
Copy link

tao commented Nov 24, 2022

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
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants