Skip to content

Commit

Permalink
Merge #161
Browse files Browse the repository at this point in the history
161: Changes related to the next MeiliSearch release (v0.21.0) r=alallema a=meili-bot

Related to this issue: meilisearch/integration-guides#117

This PR:
- gathers the changes related to the next MeiliSearch release (v0.21.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases). Until there is an RC version, the tests should be valid against the [alpha versions of transplant](https://github.com/meilisearch/transplant/releases).
- might eventually contain test failures until the MeiliSearch v0.21.0 is out.

⚠️ This PR should NOT be merged until the next release of MeiliSearch (v0.21.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose. Exceptionally for this release, the pre-release time will be more than just one week._

Done:
- Update README and code sample #188 #195 #196 
- Update `waitForPendingUpdate` status #189 
- Rename `attributesForFaceting` into `filterableAttributes` #190
- Adapts tests according to v0.21.0 breaking changes #191 
  - Rename `buildDate` into `commitDate`
  - Rename `fieldsDistribution` into `fieldDiestribution`
  - Update `rankingRules`
- Fix tests and Add missing tests according to new features #192 #194
    - Add phrase search tests
    - Add search test including filter with number
    - Test with filter as an array

Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com>
Co-authored-by: Amélie <alallema@users.noreply.github.com>
Co-authored-by: alallema <amelie@meilisearch.com>
  • Loading branch information
4 people authored Aug 24, 2021
2 parents 5564333 + 7b939b7 commit ef4cd3e
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 182 deletions.
67 changes: 33 additions & 34 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,11 +65,10 @@ get_settings_1: |-
update_settings_1: |-
$client->index('movies')->updateSettings([
'rankingRules' => [
'typo',
'words',
'typo',
'proximity',
'attribute',
'wordsPosition',
'exactness',
'desc(release_date)',
'desc(rank)'
Expand Down Expand Up @@ -118,11 +117,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)'
Expand All @@ -135,6 +133,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: |-
Expand All @@ -145,15 +152,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: |-
Expand Down Expand Up @@ -189,42 +187,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)'
Expand Down Expand Up @@ -254,7 +251,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:
Expand Down Expand Up @@ -287,23 +284,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', ['filter' => [['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');
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <!-- omit in toc -->
Expand Down Expand Up @@ -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
```
Expand All @@ -149,20 +148,24 @@ JSON output:
{
"hits": [
{
"book_id": 456,
"title": "Le Petit Prince"
"book_id": 1344,
"title": "The Hobbit",
"_formatted": {
"book_id": 1344,
"title": "The <em>Hob</em>bit"
}
}
],
"offset": 0,
"limit": 20,
"processingTimeMs": 10,
"query": "prince"
"processingTimeMs": 0,
"query": "hob"
}
```

## 🤖 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

Expand Down
14 changes: 7 additions & 7 deletions src/Endpoints/Delegates/HandlesSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
2 changes: 1 addition & 1 deletion src/Endpoints/Indexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] && 'processing' != $res['status']) {
return $res;
}
$timeout_temp += $intervalInMs;
Expand Down
22 changes: 0 additions & 22 deletions src/Search/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace MeiliSearch\Search;

use function array_filter;
use ArrayIterator;
use Countable;
use IteratorAggregate;
Expand Down Expand Up @@ -89,7 +88,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)
*
Expand All @@ -99,9 +97,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']);
}
Expand All @@ -127,23 +122,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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Endpoints/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Endpoints/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit ef4cd3e

Please sign in to comment.