Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit 32ed58a

Browse files
committed
fixed readme and covering with tests
1 parent 9f34529 commit 32ed58a

File tree

2 files changed

+160
-5
lines changed

2 files changed

+160
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ whereExists($field) | whereExists('unemployed') | Checks if a value is defined.
399399
whereNotExists($field) | whereNotExists('unemployed') | Checks if a value isn't defined.
400400
whereRegexp($field, $value, $flags = 'ALL') | whereRegexp('name.raw', 'A.+') | Filters records according to a given regular expression. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-regexp-query.html#regexp-syntax) you can find more about syntax.
401401
whereGeoDistance($field, $value, $distance) | whereGeoDistance('location', [-70, 40], 1000) | Filters records according to given point and distance from it. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html) you can find more about syntax.
402-
whereGeoBoundingBox($field, array $value) | whereGeoBoundingBox('location', ["top_left" => [-74.1, 40.73], "bottom_right" => [-71.12, 40.01]) | Filters records within given boundings. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html) you can find more about syntax.
402+
whereGeoBoundingBox($field, array $value) | whereGeoBoundingBox('location', ["top_left" => [-74.1, 40.73], "bottom_right" => [-71.12, 40.01]]) | Filters records within given boundings. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html) you can find more about syntax.
403403
whereGeoPolygon($field, array $points) | whereGeoPolygon('location', [[-70, 40],[-80, 30],[-90, 20]]) | Filters records within given polygon. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html) you can find more about syntax.
404404

405405
In most cases it's better to use raw fields to filter records, i.e. not analyzed fields.

tests/ElasticEngineTest.php

Lines changed: 159 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace ScoutElastic\Tests;
44

5-
use Mockery;
65
use Illuminate\Database\Eloquent\Collection;
6+
use Mockery;
77
use ScoutElastic\Builders\FilterBuilder;
88
use ScoutElastic\Builders\SearchBuilder;
99
use ScoutElastic\ElasticEngine;
@@ -606,6 +606,163 @@ public function test_if_the_search_method_with_specified_whereRegexp_clause_buil
606606
$this->addToAssertionCount(1);
607607
}
608608

609+
610+
public function test_if_the_search_method_with_specified_whereGeoDistance_clause_builds_correct_payload()
611+
{
612+
$this->mockClient()
613+
->shouldReceive('search')
614+
->with([
615+
'index' => 'test_index',
616+
'type' => 'test_table',
617+
'body' => [
618+
'query' => [
619+
'bool' => [
620+
'must' => [
621+
'match' => [
622+
'_all' => 'flat'
623+
]
624+
],
625+
'filter' => [
626+
'bool' => [
627+
'must' => [
628+
[
629+
[
630+
'geo_distance' => [
631+
'distance' => 1000,
632+
'location' => [-70, 40]
633+
]
634+
]
635+
]
636+
]
637+
]
638+
]
639+
]
640+
]
641+
]
642+
]);
643+
644+
$model = $this->mockModel();
645+
646+
$builder = (new SearchBuilder($model, 'flat'))->whereGeoDistance(
647+
'location',
648+
[-70, 40],
649+
1000
650+
);
651+
652+
$this->buildEngine()
653+
->search($builder);
654+
655+
$this->addToAssertionCount(1);
656+
}
657+
658+
public function test_if_the_search_method_with_specified_whereGeoBoundingBox_clause_builds_correct_payload()
659+
{
660+
$this->mockClient()
661+
->shouldReceive('search')
662+
->with([
663+
'index' => 'test_index',
664+
'type' => 'test_table',
665+
'body' => [
666+
'query' => [
667+
'bool' => [
668+
'must' => [
669+
'match' => [
670+
'_all' => 'flat'
671+
]
672+
],
673+
'filter' => [
674+
'bool' => [
675+
'must' => [
676+
[
677+
[
678+
'geo_bounding_box' => [
679+
'location' => [
680+
"top_left" => [-74.1, 40.73],
681+
"bottom_right" => [-71.12, 40.01]
682+
]
683+
]
684+
]
685+
]
686+
]
687+
]
688+
]
689+
]
690+
]
691+
]
692+
]);
693+
694+
$model = $this->mockModel();
695+
696+
$builder = (new SearchBuilder($model, 'flat'))->whereGeoBoundingBox(
697+
'location',
698+
[
699+
"top_left" => [-74.1, 40.73],
700+
"bottom_right" => [-71.12, 40.01]
701+
]
702+
);
703+
704+
$this->buildEngine()
705+
->search($builder);
706+
707+
$this->addToAssertionCount(1);
708+
}
709+
710+
public function test_if_the_search_method_with_specified_whereGeoPolygon_clause_builds_correct_payload()
711+
{
712+
$this->mockClient()
713+
->shouldReceive('search')
714+
->with([
715+
'index' => 'test_index',
716+
'type' => 'test_table',
717+
'body' => [
718+
'query' => [
719+
'bool' => [
720+
'must' => [
721+
'match' => [
722+
'_all' => 'flat'
723+
]
724+
],
725+
'filter' => [
726+
'bool' => [
727+
'must' => [
728+
[
729+
[
730+
'geo_polygon' => [
731+
'location' => [
732+
'points' => [
733+
[-70, 40],
734+
[-80, 30],
735+
[-90, 20]
736+
]
737+
]
738+
]
739+
]
740+
]
741+
]
742+
]
743+
]
744+
]
745+
]
746+
]
747+
]);
748+
749+
$model = $this->mockModel();
750+
751+
$builder = (new SearchBuilder($model, 'flat'))->whereGeoPolygon(
752+
'location',
753+
[
754+
[-70, 40],
755+
[-80, 30],
756+
[-90, 20]
757+
]
758+
);
759+
760+
$this->buildEngine()
761+
->search($builder);
762+
763+
$this->addToAssertionCount(1);
764+
}
765+
609766
public function test_if_the_search_method_with_specified_rule_builds_correct_payload()
610767
{
611768
$this->mockClient()
@@ -628,7 +785,7 @@ public function test_if_the_search_method_with_specified_rule_builds_correct_pay
628785

629786
$model = $this->mockModel();
630787

631-
$builder = (new SearchBuilder($model, 'John'))->rule(function($builder) {
788+
$builder = (new SearchBuilder($model, 'John'))->rule(function ($builder) {
632789
return [
633790
'must' => [
634791
'match' => [
@@ -803,12 +960,10 @@ public function test_if_the_map_method_returns_the_same_results_from_database_as
803960
$searchResults = $this->getElasticSearchResponse();
804961

805962
$model = $this->mockModel()
806-
807963
->shouldReceive('whereIn')
808964
->with('id', [1, 3])
809965
->andReturnSelf()
810966
->getMock()
811-
812967
->shouldReceive('get')
813968
->andReturn(Collection::make([
814969
$this->mockModel(['id' => 1]),

0 commit comments

Comments
 (0)