Skip to content
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

Merged
merged 1 commit into from
Aug 31, 2018
Merged

Conversation

foglcz
Copy link
Contributor

@foglcz foglcz commented Aug 28, 2018

Type Feature
Fixes issues RAD-1689
Documentation updated
BC Break YES
Tests updated yes
Notes Requires #82 to be merged first.

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 parameter filter_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.

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.
Copy link
Member

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')
Copy link
Member

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

Copy link
Contributor Author

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.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@OndraM OndraM left a 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.
Copy link
Member

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);
Copy link
Member

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 = [];
Copy link
Member

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')
Copy link
Member

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.

@foglcz foglcz force-pushed the feature/new-query-language branch 3 times, most recently from 3084d26 to e56fd1f Compare August 30, 2018 08:49
@foglcz
Copy link
Contributor Author

foglcz commented Aug 30, 2018

Updated the PR as per rebiew remarks.
ping @OndraM @jirinovak

@foglcz foglcz changed the base branch from master to feature/item-properties-in-recommendation-requests August 30, 2018 09:32
"third_string_property NOT LIKE '%bar' and " .
'bool_property = true and ' .
'nullable_property IS NULL and ' .
"'some_value' in set_property",
Copy link
Member

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 ".

@foglcz foglcz force-pushed the feature/item-properties-in-recommendation-requests branch from c3e9134 to af3d80e Compare August 31, 2018 08:09
@foglcz foglcz force-pushed the feature/item-properties-in-recommendation-requests branch 2 times, most recently from 98460d3 to 41a1327 Compare August 31, 2018 08:19
@foglcz foglcz force-pushed the feature/new-query-language branch 2 times, most recently from ebdbbbe to 44fe4cf Compare August 31, 2018 08:22
/**
* Specify the filter type being used.
*/
public function setFilterType(string $filterType): self
Copy link
Member

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.

Copy link
Contributor Author

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 :)

@foglcz foglcz force-pushed the feature/item-properties-in-recommendation-requests branch from 41a1327 to a3e5789 Compare August 31, 2018 12:31
@OndraM OndraM changed the title Add MQL support for recommendations filtering Change filtering language to MQL Aug 31, 2018
@OndraM OndraM changed the base branch from feature/item-properties-in-recommendation-requests to master August 31, 2018 13:12
@OndraM OndraM merged commit c66a7e3 into master Aug 31, 2018
@OndraM
Copy link
Member

OndraM commented Aug 31, 2018

Marged to master, thanks @foglcz 💯

@OndraM OndraM deleted the feature/new-query-language branch September 4, 2018 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants