Comments (10)
I think you just need to eager load the relations before indexing the data.
Or, what I like to do, is add the protected member $with to the model like this ...
protected $with = ['user','category','tags'];
This will automatically eager load user, category, and tags every time the model is accessed ... including when scout indexes documents.
from scout.
I have the model with relations indexed on elastic search, but, to return a search, I dont got the relations, in elasticsearch all data are there, all data of relations too. Only on search the data arent returned.
from scout.
hmm that does seem a little odd ...
from scout.
My code
// in controller
public function search($search){
return Produto::search($search)->get();
}
My model
<?php
namespace Tandle\Pedagogico\Model;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use Tandle\Support\Rules\Ativo;
class Produto extends Model
{
use Ativo, Searchable;
protected $primaryKey = 'idCurso';
protected $table = 'Curso';
public function tipoproduto()
{
return $this->belongsTo(TipoProduto::class);
}
public function instituicao()
{
return $this->belongsTo(Instituicao::class);
}
public function modulos()
{
return $this->hasMany(Modulo::class,'Curso');
}
public function disciplinas()
{
return $this->belongsToMany(Disciplina::class, 'CursoDisciplina', 'Curso','Disciplina');
}
public function alunos()
{
return $this->belongsToMany(User::class, 'CursoAluno', 'Curso','Aluno');
}
public function unidades()
{
return $this->belongsToMany(Unidade::class, 'UnidadesCursos', 'Curso','Unidade');
}
public function turmas()
{
return $this->hasMany(Turma::class, 'Curso');
}
public function searchableAs()
{
return 'produtos_index';
}
/**
* @return array
*/
public function toSearchableArray()
{
$array = $this->toArray();
$array['modulos'] =self::with(['modulos'])->get();
$array['unidades'] =self::with(['unidades'=>function($q){
$q->select('Curso');
}])->get();
$array['disciplinas'] =self::with(['disciplinas'=>function($q){
$q->orderBy('criterio_aprovacao','ASC');
}])->get();
return $array;
}
}
and result
in ES
Note the relations
And result of search
No relations from ES
from scout.
someone any idea?
from scout.
someone any idea?
from scout.
Going to close this as Elasticsearch support has been removed since. There are some third party packages on packages with an Elasticsearch engine for scout.
from scout.
Interesting, if you have a problem, you drop a tool (part of) that you created for erase the problem?
from scout.
@IgorDePaula this was 2 years ago. You're always welcome to create a full and working ElasticSearch implementation for Scout yourself if you want :)
from scout.
from scout.
Related Issues (20)
- Relationship with ManyToMany HOT 1
- Scout currently supports where clause that uses equal (=) operator only. Additional comparison (i.e >, >=, < ...) operation support is required. HOT 2
- php artisan scout:import error HOT 3
- Scout always returning an empty response but paginateRaw returns data HOT 5
- Support queryCallback in CollectionEngine HOT 1
- Formatting data based on the search field HOT 1
- Scout import command didn't indexed all the records in meilisearch HOT 1
- Meilisearch facetDistribution / raw attributes HOT 3
- Search downtime when running `scout:import` with Algolia HOT 2
- Method Laravel\Scout\Builder::withSearchParameters does not exist. HOT 7
- Typesense: Search throws exception -> fields is required HOT 5
- Typesense: Import exception not properly thrown HOT 1
- We need more operators in where clauses HOT 2
- Warn when using null driver HOT 1
- use scopeSearch to allow searching on relationships HOT 1
- Artisan scout commands not defined. HOT 1
- Add a fake() for scout HOT 4
- Exception when searching large datasets for common query using paginate HOT 12
- Searchable not sync to meilisearch with other index HOT 1
- Laravel 11 Support? 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 scout.