babenkoivan / elastic-scout-driver-plus

Extension for Elastic Scout Driver
MIT License
267 stars 52 forks source link

Add `when()` method on `QueryBuilder` classes #120

Closed 2Seg closed 2 years ago

2Seg commented 2 years ago

Hello! 👋

I'm implementing this package since babenkoivan/scout-elasticsearch-driver is archived. Don't you think it would be interesting to also implement a when() method on AbstractParameterizedQueryBuilder so that we could call it on child classes such as BoolQueryBuilder for instance?

All these child classes are final and not macroable so I can't see a way to implement it on my own.

Here is an exemple :

Query::bool()
    ->when(true, function ($query) {
        return $query->must(...)
    })
    ->when(false, function ($query) {
        return $query->filter(...)
    })

Thanks for the great work! Cheers, Eliott

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

babenkoivan commented 2 years ago

Hi @2Seg, I've just released v4.0.0 that supports when and unless methods for query builders 🎉

2Seg commented 2 years ago

Thanks @babenkoivan!! 🤩