Giter VIP home page Giter VIP logo

Comments (8)

huglester avatar huglester commented on May 23, 2024

same here, I do want to port some custom sollution to Scount.

what I want now, is sort like this:

'sort' => [
    [
        'created_at' => [
            'order' => 'desc',
        ],
        'id' => [
            'order' => 'desc',
        ],
    ],
],

is there any option to achieve this at the moment?

from laravel-scout-elastic.

thomasjsn avatar thomasjsn commented on May 23, 2024

It's a bit tricky passing parameters to the engine, because one has to adhere to the Scout engine base class. I have made some changes to the query and filtering, which I think has made the search return better results, and faster. But nothing on sorting, yet...

from laravel-scout-elastic.

thomasjsn avatar thomasjsn commented on May 23, 2024

@huglester You could just fork it and make your own special implementation of course.

from laravel-scout-elastic.

thomasjsn avatar thomasjsn commented on May 23, 2024

@ErickTamayo Hey, I've forked and made some changes to the search query which I think returns much better results, faster.

  • Remove asterisk wildcards from beginning and end of query, they make the search slower and make it impossible to use certain boolean operators.

In order to prevent extremely slow wildcard queries, a wildcard term should not start with one of the wildcards * or ?.

  • Use default operator AND instead of OR, this returns more relevant results (I think) and is closer to what Algolia returns.

  • Apply Scout filters as filter instead of must. This makes it faster and does not change the scoring of the query search results. I've also changed the filter condition from match_phrase to term, which is again faster.

When used in filtering context, the query is said to be a "non-scoring" or "filtering" query. That is, the query simply asks the question: "Does this document match?". The answer is always a simple, binary yes|no.

I've also added a filter to remove results which is not present in the instances of the given model, like the Algolia engine has. That solved issue #36.

Now... The changes I have made to the query will produce different search results, which may produce unwanted results for some. But I think it's a better way of searching. Will you be accepting a PR?

Update 13.feb: I've made the search method configurable in the scout config, and overridable within search searchable model.

from laravel-scout-elastic.

huglester avatar huglester commented on May 23, 2024

Let's hope we will be able to solve this issue ar 'ELasticsearch' level.
It seems that this driver will be kinda out of sync with algolia - but anyway - this ELasticsearch is other world.

from laravel-scout-elastic.

thomasjsn avatar thomasjsn commented on May 23, 2024

I have added the ability to define different search types in the config file, or override them like this:

$articles = Article::elasticSearch('multi_match', $q, [
    'fields' => ['title', 'content', 'tags'],
    'fuzziness' => 'auto',
    'prefix_length' => 2,
    'operator' => 'AND'
])
    ->where('is_published', true)
    ->get();

Using a ElasticSearchable trait, instead of Searchable.

from laravel-scout-elastic.

huglester avatar huglester commented on May 23, 2024

Wow. As for now I think this is exactly what is needed!

SO it does support this 'fluent' syntax like: where('is_published', true)?
this is awesome.

from laravel-scout-elastic.

thomasjsn avatar thomasjsn commented on May 23, 2024

@huglester The where method is just the filter, as is implemented in the driver today. The "fluent" part is the Elasticsearch field name, the Article model has a boolean field called is_published. Very readable :)

I'm planning to submit a PR after I've done some more testing.

from laravel-scout-elastic.

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.