-
-
Notifications
You must be signed in to change notification settings - Fork 114
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 possibility to use instances of classes that implement ONGR\ElasticsearchDSL\BuilderInterface as values for where() in Laravel Scout query builder #260
Conversation
…icsearchDSL\BuilderInterface as values for where() in Laravel Scout query builder
…icsearchDSL\BuilderInterface as values for where() in Laravel Scout query builder
Thanks @swayok. This is nice to solve this problem, and I appreciate your effort. Could we write a test to see when the problem happened and what we solved exactly in this PR? |
@hkulekci added test case for RangeQuery but I wasn't able to run it. |
@matchish could you approve to be able to see test results? |
Codecov ReportAll modified lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #260 +/- ##
============================================
+ Coverage 96.06% 96.08% +0.01%
- Complexity 192 193 +1
============================================
Files 36 36
Lines 636 638 +2
============================================
+ Hits 611 613 +2
Misses 25 25
☔ View full report in Codecov by Sentry. |
LGTM. I prefer splitting the tests into different functions. But at least for now, it shows that the implementation is working. If you can, please could you move the test into a new test function as below : public function test_search_with_custom_filter()
{
$dispatcher = Product::getEventDispatcher();
Product::unsetEventDispatcher();
$kindleCheapAmount = rand(1, 5);
$iphoneLuxuryAmount = rand(1, 5);
$iphonePromoUsedAmount = rand(1, 5);
$iphonePromoNewAmount = rand(6, 10);
$iphonePromoLikeNewAmount = rand(1, 5);
$iphonePromoUsedAndLikeNewAmount = $iphonePromoLikeNewAmount + $iphonePromoUsedAmount;
factory(Product::class, $kindleCheapAmount)->states(['iphone', 'cheap'])->create();
factory(Product::class, $iphoneLuxuryAmount)->states(['iphone', 'luxury'])->create();
factory(Product::class, $iphonePromoUsedAmount)->states(['iphone', 'promo', 'used'])->create();
factory(Product::class, $iphonePromoNewAmount)->states(['iphone', 'promo', 'new'])->create();
factory(Product::class, $iphonePromoLikeNewAmount)->states(['iphone', 'promo', 'like new'])->create();
Product::setEventDispatcher($dispatcher);
Artisan::call('scout:import');
// Promo Product Test
$iphonePromoUsedAndLikeNewWithRange = Product::search('iphone')
->where('price', new RangeQuery('price', [
RangeQuery::GTE => 100, // Promo Products
RangeQuery::LTE => 100, // Promo Products
]))
->whereIn('type', ['used', 'like new'])
->get();
$this->assertEquals($iphonePromoUsedAndLikeNewWithRange->count(), $iphonePromoUsedAndLikeNewAmount);
$this->assertInstanceOf(Product::class, $iphonePromoUsedAndLikeNewWithRange->first(), 'Promo Product Assert');
// Luxury Product Test
$iphoneLuxuryUsedAndLikeNewWithRange = Product::search('iphone')
->where('price', new RangeQuery('price', [
RangeQuery::GTE => 1000, // Luxury Products
]))
->get();
$this->assertEquals($iphoneLuxuryUsedAndLikeNewWithRange->count(), $iphoneLuxuryAmount, 'Luxury Product Count Assert');
$this->assertInstanceOf(Product::class, $iphoneLuxuryUsedAndLikeNewWithRange->first());
// Cheap Product Test
$iphoneCheapWithRange = Product::search('iphone')
->where('price', new RangeQuery('price', [
RangeQuery::LTE => 70, // Cheap Products
]))
->get();
$this->assertEquals($kindleCheapAmount, $iphoneCheapWithRange->count(), 'Cheap Product Count Assert');
$this->assertInstanceOf(Product::class, $iphoneCheapWithRange->first());
} Thanks @swayok. ^_^ |
And could you update README plz? |
Done |
Released! Thanks @swayok. Really nice feature |
For #259