-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial functional tests #1
Conversation
@sstok is this something you had in mind? |
bacfdde
to
7728c19
Compare
.gitignore
Outdated
@@ -1,3 +1,4 @@ | |||
/.idea/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this, you can use the global .gitignore instead 👍
https://help.github.com/articles/ignoring-files/#create-a-global-gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks for the link.
Thank you so much for your work so far 👍 |
@sstok can you elaborate a bit on the ie. how do I map from fieldset |
protected function configureConditionGenerator(QueryConditionGenerator $conditionGenerator) | ||
{ | ||
// TODO: mapping field set alias to Elasticsearch property | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sstok this is where I'm hoping you can shed some light. :)
$conditionGenerator = new QueryConditionGenerator($condition); | ||
$this->configureConditionGenerator($conditionGenerator); | ||
|
||
// TODO: where do I get these from? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sstok also here, don't quite understand how you imagined for it to work.
The It's a while since I worked on the ElasticSearch implementation 😅 |
30b2b28
to
2e857c2
Compare
@sstok sure, we can work on advanced mappings later, for now let's try and get anything working. :) For example, how did you imagine we map |
@@ -15,7 +15,7 @@ return PhpCsFixer\Config::create() | |||
'@Symfony:risky' => true, | |||
'@PHP70Migration' => true, | |||
'@PHP71Migration' => true, | |||
'array_syntax' => array('syntax' => 'short'), | |||
'array_syntax' => ['syntax' => 'short'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is ironic. 😭
@sstok I've added some changes to the query generator itself:
Can you take a look and point out any glaring errors or do you feel this might be a way to go? |
I've taken the McDonald's principle and have made a property notation format proposition. If you have any feedback on this or anything else in this PR, I'd really love to hear it. Also need a review regarding normalizers (specifically date, but others too). I think this has quite some potential, need to work out the details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work so far 👍 I left some notes and idea's.
I'm away from keyboard later today. So may not be able to respond directly.
src/QueryConditionGenerator.php
Outdated
private $searchCondition; | ||
private $fieldSet; | ||
// private $fieldSet; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property is used in the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, my bad. :(
src/QueryConditionGenerator.php
Outdated
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#ranges-on-dates | ||
$values = array_values($valuesBag->getSimpleValues()); | ||
foreach ($values as $idx => $value) { | ||
$valuesBag->removeSimpleValue($idx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note a ValuesBag is not immutable, and the QueryConditionGenerator should not change the ValuesBag.
Better to clone this.
For the future: Usually when a Query generator needs something special is to use TypeExtensions with options like elastic_search_structure_transformer
which receives the ValuesBag (or ValuesGroup, or both) and allows to change it's structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you write/link an example? How do I register transformers per type (say, always transform Date like this, no matter where it is)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just working on this and it's annoying as it is, especially since it's only placeholder code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did something similar for the Doctrine DBAL integration 😋 query conversions
.
https://github.com/rollerworks/search-doctrine-dbal/blob/master/src/Query/QueryField.php#L96
For example the https://github.com/rollerworks/search-doctrine-dbal/blob/master/src/Extension/Conversion/AgeDateConversion.php allows to search with both an age and a date.
src/QueryConditionGenerator.php
Outdated
foreach ($valuesBag->get(Range::class) as $range) { | ||
$ids = array_merge($ids, range($range->getLower(), $range->getUpper())); | ||
} | ||
if (false === empty($ids)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the explicit Boolean check, you can simple use if (f!empty($ids)) {
Same goes for all other code occurrences.
src/QueryConditionGenerator.php
Outdated
|
||
$bool[$includingType][] = [$this->mappings[$fieldName]->indexName => $rangeParams]; | ||
} | ||
if (false === $isId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check needs to be done sooner as simple values can also apply to the id, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll be moving the whole thing.
return $converter->convertValue($value); | ||
} | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This phpdoc is useless, with private methods we only use it when it not directly clear what the method does or when there are some special rules/conventions. And thanks to strict types we don't need it here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I'm not a big fan of the selective decision process if a docblock is necessary. It puts burden on the developer / reviewer to figure out. My path usually is to add them everywhere, it doesn't hurt readability, but it does allow for my tooling to work better.
I'll remove it here, obviously. 👍
namespace Rollerworks\Component\Search\Elasticsearch; | ||
|
||
/** | ||
* Interface ValueConversion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to use a better description here. And don't forget to add an author tag 👍 your doing a great job here 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I think I have a good idea how we can push the functionality further. Basically, special cases can go to the per-type extension which should allow, for example, exceptions for dates and IDs while keeping the basic query generator quite simple.
It'll be probably done monday. How do you plan actually implementing the client, if not using Elastica?
Added a query conversion concept (which should handle special cases for IDs, dates, etc). Also, you've inverted less than / greater than in your code and tests, I had a WTF moment there for a bit. 😭 Check the latest changes and feedback if you get the chance. BTW how do I explain to the system that any date-y field should be converted by my DateConverter? Currently, BirthdayType is broken as it's not handled. |
It's used not only by the query conversion process
9f28f22
to
3b94110
Compare
I've added support for nested queries (for example, binding property What can we do to get this merged and released tomorrow? I'd like to include a preview version of this in my app ASAP (that's the reason I've done this work in the first place). If you could help me out here, it would be great. For example, start by submitting the package to Packagist so I can add my fork to my app. Thanks. |
Amazing work! This looks good enough to move forwards. About the Client part, I didn't want to force a specific client implementation to use the user. For the API-Platform we need a full integration (using Elastica) to also make the mapping of Resources to Indexes/Documents work. But I'm not sure what the best approach is for this. |
\o/ Could you submit the package to Packagist, it would allow us to move forward on this.
Maybe require FOS Elastica Bundle and compiler-pass the mapping into it? |
I'm going to merge this one so we can move forward 👍 |
Thank you @dkarlovi |
Wait, I'm pushing more stuff! |
OK, opening a new PR. :) |
No problem ;) I can even give you push access to this repository as you did an amazing job and I don't have always time to review everything in detail 😄 Basically I have a few rules (I still need to formalize these):
When in doubt about something feel free to ask me 👍 (I will always do a review afterwards) |
As said before, I really think you should consider a mono-repo for this project, the overhead of setup required for every single-repo will be quite high. Not that I'm requesting push access for that mono repo. :) For example, I like to setup all the infra stuff to be run from a Makefile and then can just run
That's why I'd rather you undo this merge as I've been doing WIP commits which I intended to fix afterward. |
As suggested in rollerworks/search#179