GithubHelp home page GithubHelp logo

Comments (10)

brino avatar brino commented on May 12, 2024

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.

IgorDePaula avatar IgorDePaula commented on May 12, 2024

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.

brino avatar brino commented on May 12, 2024

hmm that does seem a little odd ...

from scout.

IgorDePaula avatar IgorDePaula commented on May 12, 2024

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
es
Note the relations
And result of search
errosearch
No relations from ES

from scout.

IgorDePaula avatar IgorDePaula commented on May 12, 2024

someone any idea?

from scout.

IgorDePaula avatar IgorDePaula commented on May 12, 2024

someone any idea?

from scout.

driesvints avatar driesvints commented on May 12, 2024

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.

IgorDePaula avatar IgorDePaula commented on May 12, 2024

Interesting, if you have a problem, you drop a tool (part of) that you created for erase the problem?

from scout.

driesvints avatar driesvints commented on May 12, 2024

@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.

IgorDePaula avatar IgorDePaula commented on May 12, 2024

from scout.

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.