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

Add possibility to use instances of classes that implement ONGR\ElasticsearchDSL\BuilderInterface as values for where() in Laravel Scout query builder #260

Merged
merged 5 commits into from
Oct 12, 2023

Conversation

swayok
Copy link
Contributor

@swayok swayok commented Oct 6, 2023

For #259

Filippov Alexander added 2 commits October 6, 2023 14:41
…icsearchDSL\BuilderInterface as values for where() in Laravel Scout query builder
…icsearchDSL\BuilderInterface as values for where() in Laravel Scout query builder
@hkulekci
Copy link
Contributor

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?

@swayok
Copy link
Contributor Author

swayok commented Oct 10, 2023

@hkulekci added test case for RangeQuery but I wasn't able to run it.

@hkulekci
Copy link
Contributor

@matchish could you approve to be able to see test results?

@hkulekci
Copy link
Contributor

@hkulekci added test case for RangeQuery but I wasn't able to run it.

Hey @swayok thanks for the quick response and the tests. Let's wait for @matchish. I hope he will approve soon.

@codecov-commenter
Copy link

codecov-commenter commented Oct 10, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (97e5578) 96.06% compared to head (ac3b9ff) 96.08%.

❗ 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              
Files Coverage Δ
src/ElasticSearch/SearchFactory.php 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hkulekci
Copy link
Contributor

hkulekci commented Oct 11, 2023

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. ^_^

@matchish
Copy link
Owner

matchish commented Oct 11, 2023

And could you update README plz?

@swayok
Copy link
Contributor Author

swayok commented Oct 11, 2023

Done

@hkulekci
Copy link
Contributor

Hey, @swayok, thanks for the quick update. I appreciate it.

@matchish LGTM!

@matchish matchish merged commit 0a5dfc8 into matchish:master Oct 12, 2023
3 checks passed
@matchish
Copy link
Owner

Released! Thanks @swayok. Really nice feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants