From 81713e6b2b704ee0544d686f4896c642df6238b8 Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Tue, 27 Apr 2021 15:27:30 +0200 Subject: [PATCH 01/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fe4e95fc..4098896f 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ JSON output: ## 🤖 Compatibility with MeiliSearch -This package only guarantees the compatibility with the [version v0.20.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.20.0). +This package only guarantees the compatibility with the [version v0.21.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.21.0). ## 💡 Learn More From 6688afca986cbbdf0034173f1e8f4e345d64832c Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 13 Jul 2021 14:10:05 +0200 Subject: [PATCH 02/11] Update README and code samples --- .code-samples.meilisearch.yaml | 69 +++++++++++++++++----------------- README.md | 17 +++++---- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 1450d1db..366a262b 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -10,9 +10,9 @@ list_all_indexes_1: |- create_an_index_1: |- $client->createIndex('movies', ['primaryKey' => 'movie_id']); update_an_index_1: |- - $client->updateIndex('movies', ['primaryKey' => 'movie_id']); + $client->updateIndex('movies', ['primaryKey' => 'movie_review_id']); // OR - $client->index('movies')->update(['primaryKey' => 'movie_id']); + $client->index('movies')->update(['primaryKey' => 'movie_review_id']); delete_an_index_1: |- $client->deleteIndex('movies'); // OR @@ -54,6 +54,8 @@ search_post_1: |- // Get the decoded response of MeiliSearch, see response below $response = $searchResults->getRaw(); +search_get_1: |- + $client->index('movies')->search('american ninja'); get_update_1: |- $client->index('movies')->getUpdateStatus(1); get_all_updates_1: |- @@ -65,11 +67,10 @@ get_settings_1: |- update_settings_1: |- $client->index('movies')->updateSettings([ 'rankingRules' => [ - 'typo', 'words', + 'typo', 'proximity', 'attribute', - 'wordsPosition', 'exactness', 'desc(release_date)', 'desc(rank)' @@ -118,11 +119,10 @@ get_ranking_rules_1: |- $client->index('movies')->getRankingRules(); update_ranking_rules_1: |- $client->index('movies')->updateRankingRules([ - 'typo', 'words', + 'typo', 'proximity', 'attribute', - 'wordsPosition', 'exactness', 'asc(release_date)', 'desc(rank)' @@ -135,6 +135,15 @@ update_distinct_attribute_1: |- $client->index('movies')->updateDistinctAttribute('movie_id'); reset_distinct_attribute_1: |- $client->index('movies')->resetDistinctAttribute(); +get_filterable_attributes_1: |- + $client->index('movies')->getFilterableAttributes(); +update_filterable_attributes_1: |- + $client->index('movies')->updateFilterableAttributes([ + 'genres', + 'director' + ]); +reset_filterable_attributes_1: |- + $client->index('movies')->resetFilterableAttributes(); get_searchable_attributes_1: |- $client->index('movies')->getSearchableAttributes(); update_searchable_attributes_1: |- @@ -145,15 +154,6 @@ update_searchable_attributes_1: |- ]); reset_searchable_attributes_1: |- $client->index('movies')->resetSearchableAttributes(); -get_attributes_for_faceting_1: |- - $client->index('movies')->getAttributesForFaceting(); -update_attributes_for_faceting_1: |- - $client->index('movies')->updateAttributesForFaceting([ - 'genres', - 'director' - ]); -reset_attributes_for_faceting_1: |- - $client->index('movies')->resetAttributesForFaceting(); get_displayed_attributes_1: |- $client->index('movies')->getDisplayedAttributes(); update_displayed_attributes_1: |- @@ -189,42 +189,41 @@ field_properties_guide_displayed_1: |- 'release_date' ]); filtering_guide_1: |- - $client->index('movies')->search('Avengers', ['filters' => 'release_date > 795484800']); + $client->index('movies')->search('Avengers', ['filter' => 'release_date > 795484800']); filtering_guide_2: |- - $client->index('movies')->search('Avengers', ['filters' => 'release_date > 795484800 AND (director = "Tim Burton" OR director = "Christopher Nolan")']); + $client->index('movies')->search('Batman', ['filter' => 'release_date > 795484800 AND (director = "Tim Burton" OR director = "Christopher Nolan")']); filtering_guide_3: |- - $client->index('movies')->search('horror', ['filters' => 'director = "Jordan Peele"']); + $client->index('movies')->search('horror', ['filter' => 'director = "Jordan Peele"']); filtering_guide_4: |- - $client->index('movies')->search('Planet of the Apes', ['filters' => 'rating >= 3 AND (NOT director = "Tim Burton")']); + $client->index('movies')->search('Planet of the Apes', ['filter' => 'rating >= 3 AND (NOT director = "Tim Burton")']); search_parameter_guide_query_1: |- $client->index('movies')->search('shifu'); search_parameter_guide_offset_1: |- $client->index('movies')->search('shifu', ['offset' => 1]); search_parameter_guide_limit_1: |- - $client->index('movies')->search('shifu', ['limit' => 1]); + $client->index('movies')->search('shifu', ['limit' => 2]); search_parameter_guide_retrieve_1: |- $client->index('movies')->search('shifu', ['attributesToRetrieve' => ['overview', 'title']]); search_parameter_guide_crop_1: |- $client->index('movies')->search('shifu', ['attributesToCrop' => ['overview'], 'cropLength' => 10]); search_parameter_guide_highlight_1: |- - $client->index('movies')->search('shifu', ['attributesToHighlight' => ['overview']]); + $client->index('movies')->search('winter feast', ['attributesToHighlight' => ['overview']]); search_parameter_guide_filter_1: |- - $client->index('movies')->search('n', ['filters' => 'title = Nightshift']); + $client->index('movies')->search('n', ['filter' => 'title = Nightshift']); search_parameter_guide_filter_2: |- - $client->index('movies')->search('shifu', ['filters' => 'title="Kung Fu Panda"']); + $client->index('movies')->search('shifu', ['filter' => 'title="Kung Fu Panda"']); search_parameter_guide_matches_1: |- - $client->index('movies')->search('shifu', ['attributesToHighlight' => ['overview'], 'matches' => true]); + $client->index('movies')->search('winter feast', ['attributesToHighlight' => ['overview'], 'matches' => true]); settings_guide_synonyms_1: |- $client->index('tops')->updateSynonyms(['sweater' => ['jumper'], 'jumper' => ['sweater']]); settings_guide_stop_words_1: |- $client->index('movies')->updateStopWords(['the', 'a', 'an']); settings_guide_ranking_rules_1: |- $client->index('movies')->updateRankingRules([ - 'typo', 'words', + 'typo', 'proximity', 'attribute', - 'wordsPosition', 'exactness', 'asc(release_date)', 'desc(rank)' @@ -254,7 +253,7 @@ documents_guide_add_movie_1: |- search_guide_1: |- $client->index('movies')->search('shifu', ['limit' => 5, 'offset' => 10]); search_guide_2: |- - $client->index('movies')->search('Avengers', ['filters' => 'release_date > 795484800']); + $client->index('movies')->search('Avengers', ['filter' => 'release_date > 795484800']); getting_started_add_documents_md: |- Using `meilisearch-php` with the Guzzle HTTP client: @@ -287,23 +286,25 @@ getting_started_search_md: |- [About this SDK](https://github.com/meilisearch/meilisearch-php/) faceted_search_update_settings_1: |- - $client->index('movies')->updateAttributesForFaceting(['director', 'genres']); -faceted_search_facet_filters_1: |- - $client->index('movies')->search('thriller', ['facetFilters' => [['genres:Horror', 'genres:Mystery']], 'director' => "Jordan Peele"']); + $client->index('movies')->updateFilterableAttributes(['director', 'genres']); +faceted_search_filter_1: |- + $client->index('movies')->search('thriller', ['filter' => [['genres:Horror', 'genres:Mystery']], 'director' => "Jordan Peele"']); faceted_search_facets_distribution_1: |- $client->index('movies')->search('Batman', ['facetsDistribution' => ['genres']]); -faceted_search_walkthrough_attributes_for_faceting_1: |- - $client->index('movies')->updateAttributesForFaceting([ +faceted_search_walkthrough_filterable_attributes_1: |- + $client->index('movies')->updateFilterableAttributes([ 'director', 'producer', 'genres', 'production_companies' ]); -faceted_search_walkthrough_facet_filters_1: |- - $client->index('movies')->search('thriller', ['facetFilters' => [['genres:Horror', 'genres:Mystery']], 'director' => "Jordan Peele"]); +faceted_search_walkthrough_filter_1: |- + $client->index('movies')->search('thriller', ['facetFilter' => [['genres:Horror', 'genres:Mystery']], 'director' => "Jordan Peele"]); faceted_search_walkthrough_facets_distribution_1: |- $client->index('movies')->search('Batman', ['facetsDistribution' => ['genres']); post_dump_1: |- $client->createDump(); get_dump_status_1: |- $client->getDumpStatus('20201101-110357260'); +phrase_search_1: |- + $client->index('movies')->search('"african american" horror'); diff --git a/README.md b/README.md index 4098896f..71343761 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ $documents = [ $index->addDocuments($documents); // => { "updateId": 0 } ``` -With the `updateId`, you can check the status (`enqueued`, `processed` or `failed`) of your documents addition using the [update endpoint](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status). +With the `updateId`, you can check the status (`enqueued`, `processing`, `processed` or `failed`) of your documents addition using the [update endpoint](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status). #### Basic Search @@ -135,10 +135,9 @@ All the supported options are described in the [search parameters](https://docs. ```php $index->search( - 'prince', + 'hob', [ 'attributesToHighlight' => ['*'], - 'filters' => 'book_id > 10' ] )->getRaw(); // Return in Array format ``` @@ -149,14 +148,18 @@ JSON output: { "hits": [ { - "book_id": 456, - "title": "Le Petit Prince" + "book_id": 1344, + "title": "The Hobbit", + "_formatted": { + "book_id": 1344, + "title": "The Hobbit" + } } ], "offset": 0, "limit": 20, - "processingTimeMs": 10, - "query": "prince" + "processingTimeMs": 0, + "query": "hob" } ``` From 096edf113d7183d7d29d80141b0d08394e362590 Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 13 Jul 2021 14:13:31 +0200 Subject: [PATCH 03/11] Add processing to waitForPendingUpdate --- src/Endpoints/Indexes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Endpoints/Indexes.php b/src/Endpoints/Indexes.php index 985ad7b6..60d8cf36 100644 --- a/src/Endpoints/Indexes.php +++ b/src/Endpoints/Indexes.php @@ -125,7 +125,7 @@ public function waitForPendingUpdate($updateId, $timeoutInMs = 5000, $intervalIn $timeout_temp = 0; while ($timeoutInMs > $timeout_temp) { $res = $this->getUpdateStatus($updateId); - if ('enqueued' != $res['status']) { + if ('enqueued' != $res['status'] && $res['status'] != 'processing') { return $res; } $timeout_temp += $intervalInMs; From c532b6e751d5ac116b29feb663ff07f6ebab96a1 Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 13 Jul 2021 14:17:19 +0200 Subject: [PATCH 04/11] Update attributeForFaceting into fiterableAttributes --- src/Endpoints/Delegates/HandlesSettings.php | 14 ++--- tests/Settings/AttributesForFacetingTest.php | 55 -------------------- tests/Settings/FilterableAttributesTest.php | 55 ++++++++++++++++++++ 3 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 tests/Settings/AttributesForFacetingTest.php create mode 100644 tests/Settings/FilterableAttributesTest.php diff --git a/src/Endpoints/Delegates/HandlesSettings.php b/src/Endpoints/Delegates/HandlesSettings.php index 49271099..e54af74d 100644 --- a/src/Endpoints/Delegates/HandlesSettings.php +++ b/src/Endpoints/Delegates/HandlesSettings.php @@ -113,20 +113,20 @@ public function resetSynonyms(): array return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/synonyms'); } - // Settings - Attributes for faceting + // Settings - Filterable Attributes - public function getAttributesForFaceting(): array + public function getFilterableAttributes(): array { - return $this->http->get(self::PATH.'/'.$this->uid.'/settings/attributes-for-faceting'); + return $this->http->get(self::PATH.'/'.$this->uid.'/settings/filterable-attributes'); } - public function updateAttributesForFaceting(array $attributesForFaceting): array + public function updateFilterableAttributes(array $FilterableAttributes): array { - return $this->http->post(self::PATH.'/'.$this->uid.'/settings/attributes-for-faceting', $attributesForFaceting); + return $this->http->post(self::PATH.'/'.$this->uid.'/settings/filterable-attributes', $FilterableAttributes); } - public function resetAttributesForFaceting(): array + public function resetFilterableAttributes(): array { - return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/attributes-for-faceting'); + return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/filterable-attributes'); } } diff --git a/tests/Settings/AttributesForFacetingTest.php b/tests/Settings/AttributesForFacetingTest.php deleted file mode 100644 index 54a5a960..00000000 --- a/tests/Settings/AttributesForFacetingTest.php +++ /dev/null @@ -1,55 +0,0 @@ -client->createIndex('index'); - - $attributes = $index->getAttributesForFaceting(); - - $this->assertIsArray($attributes); - $this->assertEmpty($attributes); - } - - public function testUpdateAttributesForFaceting(): void - { - $newAttributes = ['title']; - $index = $this->client->createIndex('index'); - - $promise = $index->updateAttributesForFaceting($newAttributes); - - $this->assertIsValidPromise($promise); - $index->waitForPendingUpdate($promise['updateId']); - - $attributesForFaceting = $index->getAttributesForFaceting(); - - $this->assertIsArray($attributesForFaceting); - $this->assertEquals($newAttributes, $attributesForFaceting); - } - - public function testResetAttributesForFaceting(): void - { - $index = $this->client->createIndex('index'); - $newAttributes = ['title']; - - $promise = $index->updateAttributesForFaceting($newAttributes); - $index->waitForPendingUpdate($promise['updateId']); - - $promise = $index->resetAttributesForFaceting(); - - $this->assertIsValidPromise($promise); - - $index->waitForPendingUpdate($promise['updateId']); - - $attributesForFaceting = $index->getAttributesForFaceting(); - $this->assertIsArray($attributesForFaceting); - $this->assertEmpty($attributesForFaceting); - } -} diff --git a/tests/Settings/FilterableAttributesTest.php b/tests/Settings/FilterableAttributesTest.php new file mode 100644 index 00000000..bc3e200b --- /dev/null +++ b/tests/Settings/FilterableAttributesTest.php @@ -0,0 +1,55 @@ +client->createIndex('index'); + + $attributes = $index->getFilterableAttributes(); + + $this->assertIsArray($attributes); + $this->assertEmpty($attributes); + } + + public function testUpdateFilterableAttributes(): void + { + $newAttributes = ['title']; + $index = $this->client->createIndex('index'); + + $promise = $index->updateFilterableAttributes($newAttributes); + + $this->assertIsValidPromise($promise); + $index->waitForPendingUpdate($promise['updateId']); + + $filterableAttributes = $index->getFilterableAttributes(); + + $this->assertIsArray($filterableAttributes); + $this->assertEquals($newAttributes, $filterableAttributes); + } + + public function testResetFilterableAttributes(): void + { + $index = $this->client->createIndex('index'); + $newAttributes = ['title']; + + $promise = $index->updateFilterableAttributes($newAttributes); + $index->waitForPendingUpdate($promise['updateId']); + + $promise = $index->resetFilterableAttributes(); + + $this->assertIsValidPromise($promise); + + $index->waitForPendingUpdate($promise['updateId']); + + $filterableAttributes = $index->getFilterableAttributes(); + $this->assertIsArray($filterableAttributes); + $this->assertEmpty($filterableAttributes); + } +} From e95e7926acb7a360bc4823dc77e2f9b2e8ee552b Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 13 Jul 2021 14:24:12 +0200 Subject: [PATCH 05/11] Fix tests --- tests/Endpoints/ClientTest.php | 2 +- tests/Endpoints/IndexTest.php | 2 +- tests/Endpoints/SearchTest.php | 208 ++++++++++++++-------------- tests/Settings/RankingRulesTest.php | 5 +- tests/Settings/SettingsTest.php | 5 +- 5 files changed, 110 insertions(+), 112 deletions(-) diff --git a/tests/Endpoints/ClientTest.php b/tests/Endpoints/ClientTest.php index aa435d52..c43ba68f 100644 --- a/tests/Endpoints/ClientTest.php +++ b/tests/Endpoints/ClientTest.php @@ -282,7 +282,7 @@ public function testVersion(): void $response = $this->client->version(); $this->assertArrayHasKey('commitSha', $response); - $this->assertArrayHasKey('buildDate', $response); + $this->assertArrayHasKey('commitDate', $response); $this->assertArrayHasKey('pkgVersion', $response); } diff --git a/tests/Endpoints/IndexTest.php b/tests/Endpoints/IndexTest.php index 0b24c638..424099e1 100644 --- a/tests/Endpoints/IndexTest.php +++ b/tests/Endpoints/IndexTest.php @@ -89,7 +89,7 @@ public function testIndexStats(): void $this->assertArrayHasKey('numberOfDocuments', $stats); $this->assertEquals(0, $stats['numberOfDocuments']); $this->assertArrayHasKey('isIndexing', $stats); - $this->assertArrayHasKey('fieldsDistribution', $stats); + $this->assertArrayHasKey('fieldDistribution', $stats); } public function testFetchInfo(): void diff --git a/tests/Endpoints/SearchTest.php b/tests/Endpoints/SearchTest.php index 90a526d6..fd15adac 100644 --- a/tests/Endpoints/SearchTest.php +++ b/tests/Endpoints/SearchTest.php @@ -139,6 +139,8 @@ public function testExceptionIfNoIndexWhenSearching(): void public function testParametersArray(): void { + $response = $this->index->updateFilterableAttributes(['title']); + $this->index->waitForPendingUpdate($response['updateId']); $response = $this->index->search('prince', [ 'limit' => 5, 'offset' => 0, @@ -146,7 +148,7 @@ public function testParametersArray(): void 'attributesToCrop' => ['id', 'title'], 'cropLength' => 6, 'attributesToHighlight' => ['title'], - 'filters' => 'title = "Le Petit Prince"', + 'filter' => 'title = "Le Petit Prince"', 'matches' => true, ]); @@ -164,7 +166,7 @@ public function testParametersArray(): void 'attributesToCrop' => ['id', 'title'], 'cropLength' => 6, 'attributesToHighlight' => ['title'], - 'filters' => 'title = "Le Petit Prince"', + 'filter' => 'title = "Le Petit Prince"', 'matches' => true, ], [ 'raw' => true, @@ -180,6 +182,8 @@ public function testParametersArray(): void public function testParametersCanBeAStar(): void { + $response = $this->index->updateFilterableAttributes(['title']); + $this->index->waitForPendingUpdate($response['updateId']); $response = $this->index->search('prince', [ 'limit' => 5, 'offset' => 0, @@ -187,7 +191,7 @@ public function testParametersCanBeAStar(): void 'attributesToCrop' => ['*'], 'cropLength' => 6, 'attributesToHighlight' => ['*'], - 'filters' => 'title = "Le Petit Prince"', + 'filter' => 'title = "Le Petit Prince"', 'matches' => true, ]); @@ -205,7 +209,7 @@ public function testParametersCanBeAStar(): void 'attributesToCrop' => ['*'], 'cropLength' => 6, 'attributesToHighlight' => ['*'], - 'filters' => 'title = "Le Petit Prince"', + 'filter' => 'title = "Le Petit Prince"', 'matches' => true, ], [ 'raw' => true, @@ -221,7 +225,7 @@ public function testParametersCanBeAStar(): void public function testBasicSearchWithFacetsDistribution(): void { - $response = $this->index->updateAttributesForFaceting(['genre']); + $response = $this->index->updateFilterableAttributes(['genre']); $this->index->waitForPendingUpdate($response['updateId']); $response = $this->index->search('prince', [ @@ -231,10 +235,9 @@ public function testBasicSearchWithFacetsDistribution(): void $this->assertArrayHasKey('facetsDistribution', $response->toArray()); $this->assertArrayHasKey('exhaustiveFacetsCount', $response->toArray()); $this->assertArrayHasKey('genre', $response->getFacetsDistribution()); - $this->assertTrue($response->getExhaustiveFacetsCount()); + $this->assertFalse($response->getExhaustiveFacetsCount()); $this->assertSame($response->getFacetsDistribution()['genre']['fantasy'], 1); $this->assertSame($response->getFacetsDistribution()['genre']['adventure'], 1); - $this->assertSame($response->getFacetsDistribution()['genre']['romance'], 0); $response = $this->index->search('prince', [ 'facetsDistribution' => ['genre'], @@ -245,91 +248,90 @@ public function testBasicSearchWithFacetsDistribution(): void $this->assertArrayHasKey('facetsDistribution', $response); $this->assertArrayHasKey('exhaustiveFacetsCount', $response); $this->assertArrayHasKey('genre', $response['facetsDistribution']); - $this->assertTrue($response['exhaustiveFacetsCount']); + $this->assertFalse($response['exhaustiveFacetsCount']); $this->assertSame($response['facetsDistribution']['genre']['fantasy'], 1); $this->assertSame($response['facetsDistribution']['genre']['adventure'], 1); - $this->assertSame($response['facetsDistribution']['genre']['romance'], 0); } - public function testBasicSearchWithFacetFilters(): void - { - $response = $this->index->updateAttributesForFaceting(['genre']); - $this->index->waitForPendingUpdate($response['updateId']); - - $response = $this->index->search('prince', [ - 'facetFilters' => [['genre:fantasy']], - ]); - $this->assertSame(1, $response->getHitsCount()); - $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); - $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); - $this->assertSame(4, $response->getHit(0)['id']); - - $response = $this->index->search('prince', [ - 'facetFilters' => [['genre:fantasy']], - ], [ - 'raw' => true, - ]); - $this->assertSame(1, $response['nbHits']); - $this->assertArrayNotHasKey('facetsDistribution', $response); - $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); - $this->assertSame(4, $response['hits'][0]['id']); - } - - public function testBasicSearchWithMultipleFacetFilters(): void - { - $response = $this->index->updateAttributesForFaceting(['genre']); - $this->index->waitForPendingUpdate($response['updateId']); - - $response = $this->index->search('prince', [ - 'facetFilters' => ['genre:fantasy', ['genre:fantasy', 'genre:fantasy']], - ]); - $this->assertSame(1, $response->getHitsCount()); - $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); - $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); - $this->assertSame(4, $response->getHit(0)['id']); - - $response = $this->index->search('prince', [ - 'facetFilters' => ['genre:fantasy', ['genre:fantasy', 'genre:fantasy']], - ], [ - 'raw' => true, - ]); - $this->assertSame(1, $response['nbHits']); - $this->assertArrayNotHasKey('facetsDistribution', $response); - $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); - $this->assertSame(4, $response['hits'][0]['id']); - } - - public function testCustomSearchWithFacetFiltersAndAttributesToRetrieve(): void - { - $response = $this->index->updateAttributesForFaceting(['genre']); - $this->index->waitForPendingUpdate($response['updateId']); - - $response = $this->index->search('prince', [ - 'facetFilters' => [['genre:fantasy']], - 'attributesToRetrieve' => ['id', 'title'], - ]); - $this->assertSame(1, $response->getHitsCount()); - $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); - $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); - $this->assertSame(4, $response->getHit(0)['id']); - $this->assertArrayHasKey('id', $response->getHit(0)); - $this->assertArrayHasKey('title', $response->getHit(0)); - $this->assertArrayNotHasKey('comment', $response->getHit(0)); - - $response = $this->index->search('prince', [ - 'facetFilters' => [['genre:fantasy']], - 'attributesToRetrieve' => ['id', 'title'], - ], [ - 'raw' => true, - ]); - $this->assertSame(1, $response['nbHits']); - $this->assertArrayNotHasKey('facetsDistribution', $response); - $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); - $this->assertSame(4, $response['hits'][0]['id']); - $this->assertArrayHasKey('id', $response['hits'][0]); - $this->assertArrayHasKey('title', $response['hits'][0]); - $this->assertArrayNotHasKey('comment', $response['hits'][0]); - } + // public function testBasicSearchWithFacetFilter(): void + // { + // $response = $this->index->updateFilterableAttributes(['genre']); + // $this->index->waitForPendingUpdate($response['updateId']); + + // $response = $this->index->search('prince', [ + // 'facetFilter' => [['genre:fantasy']], + // ]); + // $this->assertSame(1, $response->getHitsCount()); + // $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); + // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); + // $this->assertSame(4, $response->getHit(0)['id']); + + // $response = $this->index->search('prince', [ + // 'facetFilter' => [['genre:fantasy']], + // ], [ + // 'raw' => true, + // ]); + // $this->assertSame(1, $response['nbHits']); + // $this->assertArrayNotHasKey('facetsDistribution', $response); + // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); + // $this->assertSame(4, $response['hits'][0]['id']); + // } + + // public function testBasicSearchWithMultipleFacetFilter(): void + // { + // $response = $this->index->updateFilterableAttributes(['genre']); + // $this->index->waitForPendingUpdate($response['updateId']); + + // $response = $this->index->search('prince', [ + // 'facetFilter' => ['genre:fantasy', ['genre:fantasy', 'genre:fantasy']], + // ]); + // $this->assertSame(1, $response->getHitsCount()); + // $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); + // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); + // $this->assertSame(4, $response->getHit(0)['id']); + + // $response = $this->index->search('prince', [ + // 'facetFilter' => ['genre:fantasy', ['genre:fantasy', 'genre:fantasy']], + // ], [ + // 'raw' => true, + // ]); + // $this->assertSame(1, $response['nbHits']); + // $this->assertArrayNotHasKey('facetsDistribution', $response); + // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); + // $this->assertSame(4, $response['hits'][0]['id']); + // } + + // public function testCustomSearchWithFacetFilterAndAttributesToRetrieve(): void + // { + // $response = $this->index->updateFilterableAttributes(['genre']); + // $this->index->waitForPendingUpdate($response['updateId']); + + // $response = $this->index->search('prince', [ + // 'facetFilter' => [['genre:fantasy']], + // 'attributesToRetrieve' => ['id', 'title'], + // ]); + // $this->assertSame(1, $response->getHitsCount()); + // $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); + // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); + // $this->assertSame(4, $response->getHit(0)['id']); + // $this->assertArrayHasKey('id', $response->getHit(0)); + // $this->assertArrayHasKey('title', $response->getHit(0)); + // $this->assertArrayNotHasKey('comment', $response->getHit(0)); + + // $response = $this->index->search('prince', [ + // 'facetFilter' => [['genre:fantasy']], + // 'attributesToRetrieve' => ['id', 'title'], + // ], [ + // 'raw' => true, + // ]); + // $this->assertSame(1, $response['nbHits']); + // $this->assertArrayNotHasKey('facetsDistribution', $response); + // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); + // $this->assertSame(4, $response['hits'][0]['id']); + // $this->assertArrayHasKey('id', $response['hits'][0]); + // $this->assertArrayHasKey('title', $response['hits'][0]); + // $this->assertArrayNotHasKey('comment', $response['hits'][0]); + // } public function testBasicSerachWithRawSearch(): void { @@ -450,51 +452,49 @@ function (array $hit): bool { return 'Le Petit Prince' === $hit['title']; } $this->assertEquals('Le Petit Prince', $response['hits'][0]['title']); } - public function testBasicSearchWithRemoveZeroFacetsOption(): void + public function testBasicSearchWithFacetsOption(): void { - $response = $this->index->updateAttributesForFaceting(['genre']); + $response = $this->index->updateFilterableAttributes(['genre']); $this->index->waitForPendingUpdate($response['updateId']); $response = $this->index->search( 'prince', - ['facetsDistribution' => ['genre']], - ['removeZeroFacets' => true] + ['facetsDistribution' => ['genre']] ); $this->assertCount(2, $response->getFacetsDistribution()['genre']); $this->assertEquals(1, $response->getFacetsDistribution()['genre']['adventure']); $this->assertEquals(1, $response->getFacetsDistribution()['genre']['fantasy']); - $this->assertCount(3, $response->getRaw()['facetsDistribution']['genre']); + $this->assertCount(2, $response->getRaw()['facetsDistribution']['genre']); $this->assertEquals($response->getRaw()['hits'], $response->getHits()); - $this->assertNotEquals($response->getRaw()['facetsDistribution'], $response->getFacetsDistribution()); + $this->assertEquals($response->getRaw()['facetsDistribution'], $response->getFacetsDistribution()); } - public function testBasicSearchWithRemoveZeroFacetsOptionAndMultipleFacets(): void + public function testBasicSearchWithFacetsOptionAndMultipleFacets(): void { $response = $this->index->addDocuments([['id' => 32, 'title' => 'The Witcher', 'genre' => 'adventure', 'adaptation' => 'video game']]); $this->index->waitForPendingUpdate($response['updateId']); - $response = $this->index->updateAttributesForFaceting(['genre', 'adaptation']); + $response = $this->index->updateFilterableAttributes(['genre', 'adaptation']); $this->index->waitForPendingUpdate($response['updateId']); $response = $this->index->search( 'prince', - ['facetsDistribution' => ['genre', 'adaptation']], - ['removeZeroFacets' => true] + ['facetsDistribution' => ['genre', 'adaptation']] ); $this->assertCount(2, $response->getFacetsDistribution()['genre']); $this->assertEquals(1, $response->getFacetsDistribution()['genre']['adventure']); $this->assertEquals(1, $response->getFacetsDistribution()['genre']['fantasy']); $this->assertEquals([], $response->getFacetsDistribution()['adaptation']); - $this->assertCount(1, $response->getRaw()['facetsDistribution']['adaptation']); - $this->assertCount(3, $response->getRaw()['facetsDistribution']['genre']); + $this->assertCount(0, $response->getRaw()['facetsDistribution']['adaptation']); + $this->assertCount(2, $response->getRaw()['facetsDistribution']['genre']); $this->assertEquals($response->getRaw()['hits'], $response->getHits()); - $this->assertNotEquals($response->getRaw()['facetsDistribution'], $response->getFacetsDistribution()); + $this->assertEquals($response->getRaw()['facetsDistribution'], $response->getFacetsDistribution()); } public function testBasicSearchWithTransformFacetsDritributionOptionToFilter(): void { - $response = $this->index->updateAttributesForFaceting(['genre']); + $response = $this->index->updateFilterableAttributes(['genre']); $this->index->waitForPendingUpdate($response['updateId']); $filterAllFacets = function (array $facets): array { @@ -531,7 +531,7 @@ function (int $facetValue): bool { return 1 < $facetValue; }, public function testBasicSearchWithTransformFacetsDritributionOptionToMap(): void { - $response = $this->index->updateAttributesForFaceting(['genre']); + $response = $this->index->updateFilterableAttributes(['genre']); $this->index->waitForPendingUpdate($response['updateId']); $facetsToUpperFunc = function (array $facets): array { @@ -569,7 +569,7 @@ public function testBasicSearchWithTransformFacetsDritributionOptionToMap(): voi public function testBasicSearchWithTransformFacetsDritributionOptionToOder(): void { - $response = $this->index->updateAttributesForFaceting(['genre']); + $response = $this->index->updateFilterableAttributes(['genre']); $this->index->waitForPendingUpdate($response['updateId']); $facetsToUpperFunc = function (array $facets): array { diff --git a/tests/Settings/RankingRulesTest.php b/tests/Settings/RankingRulesTest.php index 3f115db2..54595f27 100644 --- a/tests/Settings/RankingRulesTest.php +++ b/tests/Settings/RankingRulesTest.php @@ -11,12 +11,11 @@ final class RankingRulesTest extends TestCase private $index; public const DEFAULT_RANKING_RULES = [ - 'typo', 'words', + 'typo', 'proximity', 'attribute', - 'wordsPosition', - 'exactness', + 'exactness' ]; protected function setUp(): void diff --git a/tests/Settings/SettingsTest.php b/tests/Settings/SettingsTest.php index 8b7e930c..6e6e6d75 100644 --- a/tests/Settings/SettingsTest.php +++ b/tests/Settings/SettingsTest.php @@ -9,12 +9,11 @@ final class SettingsTest extends TestCase { public const DEFAULT_RANKING_RULES = [ - 'typo', 'words', + 'typo', 'proximity', 'attribute', - 'wordsPosition', - 'exactness', + 'exactness' ]; public const DEFAULT_SEARCHABLE_ATTRIBUTES = ['*']; From c91e7118b06b1fdf6dc409503a00bcdf84ba276f Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 13 Jul 2021 14:28:47 +0200 Subject: [PATCH 06/11] Fix linter --- src/Endpoints/Indexes.php | 2 +- tests/Settings/RankingRulesTest.php | 2 +- tests/Settings/SettingsTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Endpoints/Indexes.php b/src/Endpoints/Indexes.php index 60d8cf36..4c02b4d1 100644 --- a/src/Endpoints/Indexes.php +++ b/src/Endpoints/Indexes.php @@ -125,7 +125,7 @@ public function waitForPendingUpdate($updateId, $timeoutInMs = 5000, $intervalIn $timeout_temp = 0; while ($timeoutInMs > $timeout_temp) { $res = $this->getUpdateStatus($updateId); - if ('enqueued' != $res['status'] && $res['status'] != 'processing') { + if ('enqueued' != $res['status'] && 'processing' != $res['status']) { return $res; } $timeout_temp += $intervalInMs; diff --git a/tests/Settings/RankingRulesTest.php b/tests/Settings/RankingRulesTest.php index 54595f27..fe28d8be 100644 --- a/tests/Settings/RankingRulesTest.php +++ b/tests/Settings/RankingRulesTest.php @@ -15,7 +15,7 @@ final class RankingRulesTest extends TestCase 'typo', 'proximity', 'attribute', - 'exactness' + 'exactness', ]; protected function setUp(): void diff --git a/tests/Settings/SettingsTest.php b/tests/Settings/SettingsTest.php index 6e6e6d75..3cc2b715 100644 --- a/tests/Settings/SettingsTest.php +++ b/tests/Settings/SettingsTest.php @@ -13,7 +13,7 @@ final class SettingsTest extends TestCase 'typo', 'proximity', 'attribute', - 'exactness' + 'exactness', ]; public const DEFAULT_SEARCHABLE_ATTRIBUTES = ['*']; From 98e2be5ca7cc935aad241969d0e63aefeaa9495f Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 13 Jul 2021 16:22:33 +0200 Subject: [PATCH 07/11] Add new tests --- src/Search/SearchResult.php | 21 ------ tests/Endpoints/SearchTest.php | 112 +++++++++--------------------- tests/Search/SearchResultTest.php | 12 ---- 3 files changed, 33 insertions(+), 112 deletions(-) diff --git a/src/Search/SearchResult.php b/src/Search/SearchResult.php index 8d4a8ada..975ca522 100644 --- a/src/Search/SearchResult.php +++ b/src/Search/SearchResult.php @@ -89,7 +89,6 @@ public function __construct(array $body) * Return a new {@see SearchResult} instance. * * The $options parameter is an array, and the following keys are accepted: - * - removeZeroFacets (boolean) * - transformFacetsDistribution (callable) * - transformHits (callable) * @@ -99,9 +98,6 @@ public function __construct(array $body) */ public function applyOptions($options): self { - if (\array_key_exists('removeZeroFacets', $options) && true === $options['removeZeroFacets']) { - $this->removeZeroFacets(); - } if (\array_key_exists('transformHits', $options) && \is_callable($options['transformHits'])) { $this->transformHits($options['transformHits']); } @@ -127,23 +123,6 @@ public function transformFacetsDistribution(callable $callback): self return $this; } - public function removeZeroFacets(): self - { - $filterAllFacets = function (array $facets): array { - $filterOneFacet = function (array $facet): array { - return array_filter( - $facet, - function (int $facetValue): bool { return 0 !== $facetValue; }, - ARRAY_FILTER_USE_BOTH - ); - }; - - return array_map($filterOneFacet, $facets); - }; - - return $this->transformFacetsDistribution($filterAllFacets); - } - public function getHit(int $key, $default = null) { return $this->hits[$key] ?? $default; diff --git a/tests/Endpoints/SearchTest.php b/tests/Endpoints/SearchTest.php index fd15adac..a1ec76d0 100644 --- a/tests/Endpoints/SearchTest.php +++ b/tests/Endpoints/SearchTest.php @@ -141,6 +141,7 @@ public function testParametersArray(): void { $response = $this->index->updateFilterableAttributes(['title']); $this->index->waitForPendingUpdate($response['updateId']); + $response = $this->index->search('prince', [ 'limit' => 5, 'offset' => 0, @@ -184,6 +185,7 @@ public function testParametersCanBeAStar(): void { $response = $this->index->updateFilterableAttributes(['title']); $this->index->waitForPendingUpdate($response['updateId']); + $response = $this->index->search('prince', [ 'limit' => 5, 'offset' => 0, @@ -223,6 +225,29 @@ public function testParametersCanBeAStar(): void $this->assertSame('Petit Prince', $response['hits'][0]['_formatted']['title']); } + public function testSearchWithFilterCanBeInt(): void + { + $response = $this->index->updateFilterableAttributes(['id', 'genre']); + $this->index->waitForPendingUpdate($response['updateId']); + + $response = $this->index->search('prince', [ + 'filter' => 'id < 12', + ]); + + $this->assertSame(1, $response->getNbHits()); + $this->assertCount(1, $response->getHits()); + $this->assertSame(4, $response->getHit(0)['id']); + + $response = $this->index->search('', [ + 'filter' => 'genre = fantasy AND id < 12', + ]); + + $this->assertSame(2, $response->getNbHits()); + $this->assertCount(2, $response->getHits()); + $this->assertSame(1, $response->getHit(0)['id']); + $this->assertSame(4, $response->getHit(1)['id']); + } + public function testBasicSearchWithFacetsDistribution(): void { $response = $this->index->updateFilterableAttributes(['genre']); @@ -253,85 +278,14 @@ public function testBasicSearchWithFacetsDistribution(): void $this->assertSame($response['facetsDistribution']['genre']['adventure'], 1); } - // public function testBasicSearchWithFacetFilter(): void - // { - // $response = $this->index->updateFilterableAttributes(['genre']); - // $this->index->waitForPendingUpdate($response['updateId']); - - // $response = $this->index->search('prince', [ - // 'facetFilter' => [['genre:fantasy']], - // ]); - // $this->assertSame(1, $response->getHitsCount()); - // $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); - // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); - // $this->assertSame(4, $response->getHit(0)['id']); - - // $response = $this->index->search('prince', [ - // 'facetFilter' => [['genre:fantasy']], - // ], [ - // 'raw' => true, - // ]); - // $this->assertSame(1, $response['nbHits']); - // $this->assertArrayNotHasKey('facetsDistribution', $response); - // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); - // $this->assertSame(4, $response['hits'][0]['id']); - // } - - // public function testBasicSearchWithMultipleFacetFilter(): void - // { - // $response = $this->index->updateFilterableAttributes(['genre']); - // $this->index->waitForPendingUpdate($response['updateId']); - - // $response = $this->index->search('prince', [ - // 'facetFilter' => ['genre:fantasy', ['genre:fantasy', 'genre:fantasy']], - // ]); - // $this->assertSame(1, $response->getHitsCount()); - // $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); - // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); - // $this->assertSame(4, $response->getHit(0)['id']); - - // $response = $this->index->search('prince', [ - // 'facetFilter' => ['genre:fantasy', ['genre:fantasy', 'genre:fantasy']], - // ], [ - // 'raw' => true, - // ]); - // $this->assertSame(1, $response['nbHits']); - // $this->assertArrayNotHasKey('facetsDistribution', $response); - // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); - // $this->assertSame(4, $response['hits'][0]['id']); - // } - - // public function testCustomSearchWithFacetFilterAndAttributesToRetrieve(): void - // { - // $response = $this->index->updateFilterableAttributes(['genre']); - // $this->index->waitForPendingUpdate($response['updateId']); - - // $response = $this->index->search('prince', [ - // 'facetFilter' => [['genre:fantasy']], - // 'attributesToRetrieve' => ['id', 'title'], - // ]); - // $this->assertSame(1, $response->getHitsCount()); - // $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); - // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); - // $this->assertSame(4, $response->getHit(0)['id']); - // $this->assertArrayHasKey('id', $response->getHit(0)); - // $this->assertArrayHasKey('title', $response->getHit(0)); - // $this->assertArrayNotHasKey('comment', $response->getHit(0)); - - // $response = $this->index->search('prince', [ - // 'facetFilter' => [['genre:fantasy']], - // 'attributesToRetrieve' => ['id', 'title'], - // ], [ - // 'raw' => true, - // ]); - // $this->assertSame(1, $response['nbHits']); - // $this->assertArrayNotHasKey('facetsDistribution', $response); - // $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); - // $this->assertSame(4, $response['hits'][0]['id']); - // $this->assertArrayHasKey('id', $response['hits'][0]); - // $this->assertArrayHasKey('title', $response['hits'][0]); - // $this->assertArrayNotHasKey('comment', $response['hits'][0]); - // } + public function testSearchWithPhraseSearch(): void + { + $response = $this->index->rawSearch('coco "harry"'); + + $this->assertCount(1, $response['hits']); + $this->assertEquals(4, $response['hits'][0]['id']); + $this->assertEquals('Harry Potter and the Half-Blood Prince', $response['hits'][0]['title']); + } public function testBasicSerachWithRawSearch(): void { diff --git a/tests/Search/SearchResultTest.php b/tests/Search/SearchResultTest.php index c96d0056..cb65a080 100644 --- a/tests/Search/SearchResultTest.php +++ b/tests/Search/SearchResultTest.php @@ -227,16 +227,4 @@ public function testTransformFacetsDritributionMethod(): void $this->assertEquals(1, $response->getFacetsDistribution()['genre']['FANTASY']); $this->assertEquals(1, $response->getFacetsDistribution()['genre']['ADVENTURE']); } - - public function testRemoveZeroFacetsMethod(): void - { - $response = $this->resultWithFacets->removeZeroFacets(); - - $this->assertCount(2, $response->getFacetsDistribution()['genre']); - $this->assertEquals(1, $response->getFacetsDistribution()['genre']['adventure']); - $this->assertEquals(1, $response->getFacetsDistribution()['genre']['fantasy']); - $this->assertCount(3, $response->getRaw()['facetsDistribution']['genre']); - $this->assertEquals($response->getRaw()['hits'], $response->getHits()); - $this->assertNotEquals($response->getRaw()['facetsDistribution'], $response->getFacetsDistribution()); - } } From 6297578c8331d8b3d04dc619909c809622fa22f2 Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 13 Jul 2021 16:26:48 +0200 Subject: [PATCH 08/11] Fix linter --- src/Search/SearchResult.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Search/SearchResult.php b/src/Search/SearchResult.php index 975ca522..27f8c695 100644 --- a/src/Search/SearchResult.php +++ b/src/Search/SearchResult.php @@ -4,7 +4,6 @@ namespace MeiliSearch\Search; -use function array_filter; use ArrayIterator; use Countable; use IteratorAggregate; From 291544e31380f05c9b77d4d0fdb2c2f641c2a960 Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 20 Jul 2021 16:50:24 +0200 Subject: [PATCH 09/11] Fix filter test --- tests/Endpoints/SearchTest.php | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tests/Endpoints/SearchTest.php b/tests/Endpoints/SearchTest.php index a1ec76d0..7f363005 100644 --- a/tests/Endpoints/SearchTest.php +++ b/tests/Endpoints/SearchTest.php @@ -278,6 +278,86 @@ public function testBasicSearchWithFacetsDistribution(): void $this->assertSame($response['facetsDistribution']['genre']['adventure'], 1); } + public function testBasicSearchWithFilters(): void + { + $response = $this->index->updateFilterableAttributes(['genre']); + $this->index->waitForPendingUpdate($response['updateId']); + + $response = $this->index->search('prince', [ + 'filter' => [['genre = fantasy']], + ]); + $this->assertSame(1, $response->getHitsCount()); + $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); + $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); + $this->assertSame(4, $response->getHit(0)['id']); + + $response = $this->index->search('prince', [ + 'filter' => [['genre = fantasy']], + ], [ + 'raw' => true, + ]); + $this->assertSame(1, $response['nbHits']); + $this->assertArrayNotHasKey('facetsDistribution', $response); + $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); + $this->assertSame(4, $response['hits'][0]['id']); + } + + public function testBasicSearchWithMultipleFilter(): void + { + $response = $this->index->updateFilterableAttributes(['genre']); + $this->index->waitForPendingUpdate($response['updateId']); + + $response = $this->index->search('prince', [ + 'filter' => ['genre = fantasy', ['genre = fantasy', 'genre = fantasy']], + ]); + $this->assertSame(1, $response->getHitsCount()); + $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); + $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); + $this->assertSame(4, $response->getHit(0)['id']); + + $response = $this->index->search('prince', [ + 'filter' => ['genre = fantasy', ['genre = fantasy', 'genre = fantasy']], + ], [ + 'raw' => true, + ]); + $this->assertSame(1, $response['nbHits']); + $this->assertArrayNotHasKey('facetsDistribution', $response); + $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); + $this->assertSame(4, $response['hits'][0]['id']); + } + + public function testCustomSearchWithFilterAndAttributesToRetrieve(): void + { + $response = $this->index->updateFilterableAttributes(['genre']); + $this->index->waitForPendingUpdate($response['updateId']); + + $response = $this->index->search('prince', [ + 'filter' => [['genre = fantasy']], + 'attributesToRetrieve' => ['id', 'title'], + ]); + $this->assertSame(1, $response->getHitsCount()); + $this->assertArrayNotHasKey('facetsDistribution', $response->getRaw()); + $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response->getRaw()); + $this->assertSame(4, $response->getHit(0)['id']); + $this->assertArrayHasKey('id', $response->getHit(0)); + $this->assertArrayHasKey('title', $response->getHit(0)); + $this->assertArrayNotHasKey('comment', $response->getHit(0)); + + $response = $this->index->search('prince', [ + 'filter' => [['genre = fantasy']], + 'attributesToRetrieve' => ['id', 'title'], + ], [ + 'raw' => true, + ]); + $this->assertSame(1, $response['nbHits']); + $this->assertArrayNotHasKey('facetsDistribution', $response); + $this->assertArrayNotHasKey('exhaustiveFacetsCount', $response); + $this->assertSame(4, $response['hits'][0]['id']); + $this->assertArrayHasKey('id', $response['hits'][0]); + $this->assertArrayHasKey('title', $response['hits'][0]); + $this->assertArrayNotHasKey('comment', $response['hits'][0]); + } + public function testSearchWithPhraseSearch(): void { $response = $this->index->rawSearch('coco "harry"'); From d405d6ece2d8bf8a6206a528b0e2623ccf2ac750 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 21 Jul 2021 10:49:06 +0200 Subject: [PATCH 10/11] Fix code sample --- .code-samples.meilisearch.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index da3a979e..854806bb 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -54,8 +54,6 @@ search_post_1: |- // Get the decoded response of MeiliSearch, see response below $response = $searchResults->getRaw(); -search_get_1: |- - $client->index('movies')->search('american ninja'); get_update_1: |- $client->index('movies')->getUpdateStatus(1); get_all_updates_1: |- From 865c1534cfd001a3703e57951061d64396a5abb2 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 21 Jul 2021 10:55:59 +0200 Subject: [PATCH 11/11] Fix code sample --- .code-samples.meilisearch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 854806bb..2d250ce5 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -297,7 +297,7 @@ faceted_search_walkthrough_filterable_attributes_1: |- 'production_companies' ]); faceted_search_walkthrough_filter_1: |- - $client->index('movies')->search('thriller', ['facetFilter' => [['genres:Horror', 'genres:Mystery']], 'director' => "Jordan Peele"]); + $client->index('movies')->search('thriller', ['filter' => [['genres:Horror', 'genres:Mystery']], 'director' => "Jordan Peele"]); faceted_search_walkthrough_facets_distribution_1: |- $client->index('movies')->search('Batman', ['facetsDistribution' => ['genres']); post_dump_1: |-