-
Notifications
You must be signed in to change notification settings - Fork 7
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
Change filtering language to MQL #84
Conversation
d0aa3be
to
78f90dc
Compare
CHANGELOG.md
Outdated
### Fixed | ||
- Exceptions occurring during async request now generate rejected promise (as they should) and are no longer thrown directly. | ||
|
||
### Added | ||
- `UserRecommendation` now sends which item properties should be returned alongside with item_ids. | ||
- **BC BREAK** | `UserRecommendation` now uses MQL query language by default for filtering. |
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.
Maybe this should be in Changed
section.
README.md
Outdated
|
||
```php | ||
$recommendation = UserRecommendation::create('user-id', 5, 'test-scenario', 1.0, 3600, ['item_id', 'item_url') | ||
->addProperty('item_title') |
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.
typo addResponseProperty
according to text above
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.
Good catch! thanks :)
README.md
Outdated
// } | ||
``` | ||
|
||
Matej will always return `item_id`, even if you don't ask for it explicitly. |
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.
What will be return when i do not request any response properties? Only item_id
or all item properties?
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.
Matej will return only item_id
- but in the new format of array of stdClass
-es.
I've updated the doc to be more explicit.
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 missing some examples and documentation of the filters in README, do you plan to add it? (or later?)
@@ -63,6 +65,7 @@ public function shouldUseCustomParameters(): void | |||
'hard_rotation' => true, | |||
'min_relevance' => UserRecommendation::MINIMAL_RELEVANCE_HIGH, | |||
'filter' => 'foo = bar and baz = ban', | |||
// when a filter type is RGX, the parameter is absent. |
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.
which parameter?
(I know which, but its not obvious from the comment :) )
*/ | ||
public function setFilterType(string $filterType): self | ||
{ | ||
Assertion::typeIdentifier($filterType); |
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.
Also assert the allowed values:
Assertion::choice(
$filterType,
[static::FILTER_TYPE_RGX, static::FILTER_TYPE_MQL]
);
(like we do in setMinimalRelevance()
etc.)
@@ -30,7 +32,9 @@ class UserRecommendation extends AbstractCommand implements UserAwareInterface | |||
/** @var string */ | |||
private $minimalRelevance = self::MINIMAL_RELEVANCE_LOW; | |||
/** @var string[] */ | |||
private $filters = ['valid_to >= NOW']; | |||
private $filters = []; |
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.
Also phpdoc of addFilter()
and setFilters()
method needs to be updated to reflect this change (= there is no default filter).
@@ -77,14 +80,14 @@ public function shouldAssembleFilters(): void | |||
$command = UserRecommendation::create('user-id', 333, 'test-scenario', 1.0, 3600); | |||
|
|||
// Default filter | |||
$this->assertSame('valid_to >= NOW', $command->jsonSerialize()['parameters']['filter']); | |||
$this->assertSame('', $command->jsonSerialize()['parameters']['filter']); | |||
|
|||
// Add custom filters to the default one | |||
$command->addFilter('foo = bar') |
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 test method tests just the legacy regexp filters, right?
I'd thus rename it (shouldAssembleLegacyRgxFilters()
or something like this) and add another one using some basic MQL filters. Test serve as documentation, and right now, there is no testcase actually using MQL filters.
3084d26
to
e56fd1f
Compare
Updated the PR as per rebiew remarks. |
"third_string_property NOT LIKE '%bar' and " . | ||
'bool_property = true and ' . | ||
'nullable_property IS NULL and ' . | ||
"'some_value' in set_property", |
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.
Maybe NOWDOC would be more readable.
Or at least i would align "
.
c3e9134
to
af3d80e
Compare
e56fd1f
to
71fb7b4
Compare
98460d3
to
41a1327
Compare
ebdbbbe
to
44fe4cf
Compare
/** | ||
* Specify the filter type being used. | ||
*/ | ||
public function setFilterType(string $filterType): self |
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 whole method seems uncovered by unit tests. I think there should be (simple) testcase for the rgx type.
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.
After discussion, we've removed this one :)
44fe4cf
to
4c51c00
Compare
41a1327
to
a3e5789
Compare
4c51c00
to
92d29c3
Compare
Marged to master, thanks @foglcz 💯 |
Adds support for Matej Query Language in the recommendation requests, which is now default way of sending requests.
Removes default filter.
Legacy filtering using regexes can be done by setting filter type to
FILTER_TYPE_RGX
. In the request itself, the legacy way of filtering is implemented by absence of parameterfilter_type
. However, we don't want to encourage Matej users to use the RGX filter, as MQL is overall faster, and implements more features. Therefore, I did not mention this explicitly in the documentation.