Comments (3)
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.
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.
Thanks for the explanation. Now I think I got the problem. Let me think
from laravel-scout-elasticsearch.
Related Issues (20)
- Laravel 10 Support HOT 7
- [Feature] v5 with forked handcraftedinthealps/elasticsearch-dsl HOT 8
- [Feature] Change app namespace call in commands HOT 2
- [BUG] Call to a member function toCodeString() on null HOT 5
- [BUG] Bulk update error when saving with boolean HOT 1
- [BUG] NoNodeAvailableException: No alive nodes. All the 1 nodes seem to be down HOT 3
- [BUG] The attribute [routing] either does not exist or was not retrieved for model [App\Models\Track]. HOT 5
- [BUG] Possibly unexpected behaviour, when using additional callback in `search` HOT 3
- [Feature] Utilize custom "options" of a builder HOT 2
- configure stopwords HOT 1
- "current.health":"RED","message":"Cluster health status changed from [YELLOW] to [RED] HOT 1
- [BUG] ProgressBar updates are posted to stderr HOT 1
- [BUG] Class Elasticsearch\Client not found HOT 3
- [Feature] Add possibility to use RangeQuery and other terms instances as value for $scoutQuery->where() HOT 2
- php artisan scout:import error? Cannot use Encore\Admin\Form as Form because the name is already in use on line 21 HOT 10
- [Feature] Use SearchableScope instead PageScope HOT 4
- PHP 8.3 support HOT 2
- is there any way to revert to the previous index state before reindexing ? HOT 3
- Elastic has prefix restrictions on reads HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-scout-elasticsearch.