GithubHelp home page GithubHelp logo

Comments (4)

matchish avatar matchish commented on May 26, 2024

I think we should configure engine here
https://github.com/laravel/scout/blob/c145b4dd752ccdda7855344981dd1815ee0ae746/src/Builder.php#L314

from laravel-scout-elasticsearch.

matchish avatar matchish commented on May 26, 2024

Or you can extend builder in your app to

$model::search($query,
    function (Client $client, Search $body) use ($model, $field) {
        $highlight = new Highlight();
        $highlight->addField($field);
        $body->addHighlight($highlight);
        return $client->search(['index' => $model->searchableAs(), 'body' => $body->toArray()]);
    })->using(new Engine(new HitsIteratorFactory))->paginate(100);

But I'm still not sure what solution is better. Or maybe we should propose to change api
in laravel/scout

from laravel-scout-elasticsearch.

matchish avatar matchish commented on May 26, 2024

Now perfect api for me looks like(no callback at all)

$model::search(new Query($term))->engine(new Engine(new ResultsFactory))->paginate(100);

Or now we can do like this

$raw = $model::search($query,
    function (Client $client, Search $body) use ($model, $field) {
        $highlight = new Highlight();
        $highlight->addField($field);
        $body->addHighlight($highlight);
        return $client->search(['index' => $model->searchableAs(), 'body' => $body->toArray()]);
    })->raw();
$resullts = new HiglightedResults($raw);

from laravel-scout-elasticsearch.

matchish avatar matchish commented on May 26, 2024

Or without changing laravel/scout api
$model::search($term)->query(new ResultsFactory)->paginate(100);

We should't choose how to map results in the engine if we have queryCallback just send to the callback raw results then ResultsFactory can map it in the right way

@booni3 Now I'm working on another issue, I'm trying to finish parallel importing so feel free to send PR if you want.

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.