GithubHelp home page GithubHelp logo

Comments (3)

matchish avatar matchish commented on June 16, 2024

Thank you) I'm not sure I got what issue you're trying to solve. Could you provide some example or even better to write a test that not pass?

from laravel-scout-elasticsearch.

krio-rogue avatar krio-rogue commented on June 16, 2024

On importing model to storage, __class_name has class name of imported model.
On searching we retrieve models by same class stored in __class_name.
Its nice for a project without any additional services (other language, other model name).
Search result will be losted when we rename model class, move model to other namespace, use several models for frontend and backend, fill elastic database with other service or try to use already existed data.

App\Models\Product::makeAllSearchable(); // __class_name is 'App\Models\Product'

class MyProduct extends Product {}
App\AnyModule\MyProduct::search()->get(); // return 'App\Models\Product' instead 'App\AnyModule\MyProduct'

Using a custom HitsIteratorAggregate with scout $builder is a quick way for retrieve in search result models with initial model class for searching.

Long way

Laravel eloquent has polymorphic with custom types https://laravel.com/docs/9.x/eloquent-relationships#custom-polymorphic-types
By default on database will saved App\Models\Product. For using custom type we update model and setup morph map.

use Illuminate\Database\Eloquent\Model;

class Product extends Model {
   protected $morphClass = 'ProductAlias'; 
use Illuminate\Database\Eloquent\Relations\Relation;
Relation::morphMap([
    'ProductAlias' => App\Models\Product::class,
]);

Eloquent will save to database 'ProductAlias' instead App\Models\Product. For retrieve assigned class for alias used Model::getActualClassNameForMorph('ProductAlias') => 'App\Models\Product'
This approach is more flexible to the organization of the code and allows you to reassign the class at any time.
This solution is not quick.

from laravel-scout-elasticsearch.

matchish avatar matchish commented on June 16, 2024

Thanks for the explanation. Now I think I got the problem. Let me think

from laravel-scout-elasticsearch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.