Skip to content

Conversation

@igoooor
Copy link
Contributor

@igoooor igoooor commented Oct 7, 2022

I can only image the effort that it is to be able to implement every single options that each query DQL offers (and to maintain it).
That's why I thought about giving the possibility to the developers to add any options they would need, that may not be available yet.
What do you think?

@erichard
Copy link
Owner

erichard commented Oct 7, 2022

I see the idea but I don't quite like the implementation with a trait for this.

I suggest the use of a new optional parameter in all constructors array $params = [] so we could create a query like this

new QueryStringQuery( query: '(foo bar) OR (bar foo)', params: [ 'unimplemented_param': value ] ] 
@igoooor
Copy link
Contributor Author

igoooor commented Oct 7, 2022

I saw your different traits so I simply copy pasted one ^^ But if you prefer the constructor approach, sure.
Would you like me to update this PR?

@erichard
Copy link
Owner

erichard commented Oct 7, 2022

Traits are for shared params across all queries

Yes please update the PR

@igoooor
Copy link
Contributor Author

igoooor commented Oct 7, 2022

Please let me know if this way is better and if you would like me to change anything.
I did my best to follow your patterns

@igoooor
Copy link
Contributor Author

igoooor commented Oct 7, 2022

Oh I realise I forgot the setter for params. I will add it

@igoooor
Copy link
Contributor Author

igoooor commented Oct 7, 2022

setter is now added.
While I was at it, I also added \Erichard\ElasticQueryBuilder\Query\QueryStringQuery::$fuzziness I hope that's ok for you

@igoooor
Copy link
Contributor Author

igoooor commented Oct 7, 2022

I would also like to add the following into \Erichard\ElasticQueryBuilder\QueryBuilder:

class QueryBuilder { ... private ?array $fields = null; public function setFields(?array $fields): self { $this->fields = $fields; return $this; } ... public function build(): array { ... if (null !== $this->fields) { $query['body']['fields'] = $this->fields; } ... } ... } 

This would allows https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#search-fields-param
Tell me if it's ok to be in the same PR, or if you prefer another one.
And possibly, the same but for highlight https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html

@igoooor
Copy link
Contributor Author

igoooor commented Oct 8, 2022

I pushed what I mentioned above, and I also added the same params logic to the QueryBuilder, so that you have all the flexibility you may need until 100% of ES features are implemented.
Please let me know if I should change anything

Copy link
Owner

@erichard erichard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this work 🙏

There is minors changes to make but this is really good and will allow us to use full Elastic API

@igoooor
Copy link
Contributor Author

igoooor commented Oct 10, 2022

I believe I implemented your changes requests

@erichard erichard changed the title add HasDefaultOptions trait Allow full Elastic API using a params argument Oct 10, 2022
@igoooor
Copy link
Contributor Author

igoooor commented Oct 12, 2022

Let me know if I can support you further in merging that PR, I assume you must be quite busy

@erichard erichard merged commit 100a28e into erichard:main Oct 12, 2022
@erichard
Copy link
Owner

Merged ! Thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants