erichard / elasticsearch-query-builder

Build query for an ElasticSearch client using a fluent interface
MIT License
39 stars 20 forks source link

WIP: V3 - refactoring #7 #12

Closed pionl closed 2 years ago

pionl commented 2 years ago
pionl commented 2 years ago

Started refactoring my code base. At this moment most of the time is rewriting Filters to Query. Its not bad and its quite easy and the code looks pretty now :) 👍

  new BoolQuery(should: [
                new BoolQuery(filter: [
                    new RangeQuery(field: PriceTermsIndex::FROM, gte: $this->from->toDateString()),
                    new RangeQuery(field: PriceTermsIndex::TO, lte: $this->to->toDateString()),
                ]),
                // If the current year has no price set we want to return it as there was no price (will work if
                // HasNumberOfNights->allowTermsWithZeroNights is true)
                new TermQuery(PriceTermsIndex::NUMBER_OF_NIGHTS_RAW, 0),
            ]),

Aggregations were easy.

erichard commented 2 years ago

This is great ! Thanks :pray:

IMHO the code is even prettier when using the static factory ;)

pionl commented 2 years ago

Need to rename the branch from v3 (composer will not allow me to reference branch name with v in it). Do you know how to do it? Otherwise I will have to make a new PR.

Is the code ok for you? (the direction). Am I missing something?

erichard commented 2 years ago

You can rename your branch with git branch -m v3 refact-v3

The direction seems OK to me but he PR is quite large to review. Maybe you can split in mutliple PRs ? Like one for PHP 8.1 migration, one for rector, one for each new Query, etc

pionl commented 2 years ago

I did rename it but the PR got close but cant edit the PR branch.

About the code review - not sure if I can do it as proposed. It is mixed because rector / phpcs fixer improved the code quality.

Any way, how migrate my codebase (apx 50 filters -> queries) and it works 👍

pionl commented 2 years ago

I think im near to finishing all changes, I've made some tweaks I needed to be able to fully customize / use query builder.

I can try to separate the changes.

erichard commented 2 years ago

@pionl I've started to review this PR. One question so far : in the constructors sometime you set a private property and othertime a public one. Is there a particular reason for having both ? Shouldn't we use only private properties ?

pionl commented 2 years ago

@pionl I've started to review this PR. One question so far : in the constructors sometime you set a private property and othertime a public one. Is there a particular reason for having both ? Shouldn't we use only private properties ?

Public - I'll check which one and try to find usage. I think I've needed them in some cases (I'm doing some additional logic -> when this aggregation is used do this with source, etc).

Maybe we can expose all to public? Support set/get + "public property" ? Or use set/get everywhere? I can make the changes with your preference.

Thank you, Martin

erichard commented 2 years ago

Maybe we can expose all to public? Support set/get + "public property" ? Or use set/get everywhere? I can make the changes with your preference.

I prefer all privates with getter/setter, I think users will expect to have theses.

erichard commented 2 years ago

I can try to separate the changes.

No need to separate anymore, I reviewed the whole thing already :)

pionl commented 2 years ago

I prefer all privates with getter/setter, I think users will expect to have theses.

Ok I'll make the changes :)

pionl commented 2 years ago

Hi @erichard, I've made the changes, I've improved the git commits and added new StatsAggregation (this commit)

Anything else?

pionl commented 2 years ago

Also I've moved the "downgrade" proof of concept to different branch

erichard commented 2 years ago

Great work ! Thanks @pionl

pionl commented 2 years ago

Thank you for the cooperation!