Skip to content

Commit

Permalink
Merge #312
Browse files Browse the repository at this point in the history
312: Changes related to the next Meilisearch release (v0.27.0) r=curquiza a=meili-bot

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

This PR:
- gathers the changes related to the next Meilisearch release (v0.27.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).
- might eventually contain test failures until the Meilisearch v0.27.0 is out.

⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.27.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._

Done:
- #313 
- #315 
- #316 
- #317 
- #318 
- #320 

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 committed May 9, 2022
2 parents c28fc1b + b950d0d commit 57303fa
Show file tree
Hide file tree
Showing 14 changed files with 439 additions and 15 deletions.
59 changes: 58 additions & 1 deletion .code-samples.meilisearch.yaml
Expand Up @@ -121,6 +121,13 @@ update_settings_1: |-
'synonyms' => [
'wolverine' => ['xmen', 'logan'],
'logan' => ['wolverine']
],
'typoTolerance' => [
'minWordSizeForTypos' => [
'oneTypo' => 8,
'twoTypos' => 10
],
'disableOnAttributes' => ['title']
]
]);
reset_settings_1: |-
Expand Down Expand Up @@ -192,6 +199,20 @@ update_displayed_attributes_1: |-
]);
reset_displayed_attributes_1: |-
$client->index('movies')->resetDisplayedAttributes();
get_typo_tolerance_1:
$client->index('books')->getTypoTolerance();
update_typo_tolerance_1: |-
$client->index('books')->updateTypoTolerance([
'minWordSizeForTypos' => [
'oneTypo' => 4,
'twoTypos' => 10
],
'disableOnAttributes' => [
'title'
]
]);
reset_typo_tolerance_1: |-
$client->index('books')->resetTypoTolerance();
get_sortable_attributes_1: |-
$client->index('books')->getSortableAttributes();
update_sortable_attributes_1: |-
Expand Down Expand Up @@ -239,9 +260,17 @@ search_parameter_guide_limit_1: |-
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]);
$client->index('movies')->search('shifu', ['attributesToCrop' => ['overview'], 'cropLength' => 5]);
search_parameter_guide_crop_marker_1: |-
$client->index('movies')->search('shifu', ['attributesToCrop' => ['overview'], 'cropMarker' => '[…]']);
search_parameter_guide_highlight_1: |-
$client->index('movies')->search('winter feast', ['attributesToHighlight' => ['overview']]);
search_parameter_guide_highlight_tag_1: |-
$client->index('movies')->search('winter feast', [
'attributesToHighlight' => ['overview'],
'highlightPreTag' => '<span class="highlight">',
'highlightPostTag' => '</span>'
]);
search_parameter_guide_matches_1: |-
$client->index('movies')->search('winter feast', ['attributesToHighlight' => ['overview'], 'matches' => true]);
settings_guide_synonyms_1: |-
Expand Down Expand Up @@ -300,6 +329,34 @@ settings_guide_sortable_1: |-
'author'
]
]);
settings_guide_typo_tolerance_1: |-
$client->index('movies')->updateTypoTolerance([
'minWordSizeForTypos' => [
'twoTypos' => 12
],
'disableOnAttributes' => [
'title'
]
]);
typo_tolerance_guide_1: |-
$client->index('movies')->updateTypoTolerance([
'enabled' => false
]);
typo_tolerance_guide_2: |-
$client->index('movies')->updateTypoTolerance([
'disableOnAttributes' => ['title']
]);
typo_tolerance_guide_3: |-
$client->index('movies')->updateTypoTolerance([
'disableOnWords' => ['shrek']
]);
typo_tolerance_guide_4: |-
$client->index('movies')->updateTypoTolerance([
'minWordSizeForTypos' => [
'oneTypo' => 4,
'twoTypos' => 10
]
]);
add_movies_json_1: |-
$moviesJson = file_get_contents('movies.json');
$movies = json_decode($moviesJson);
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-tests.yml
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Get the latest Meilisearch RC
run: echo "MEILISEARCH_VERSION=$(curl https://raw.githubusercontent.com/meilisearch/integration-guides/main/scripts/get-latest-meilisearch-rc.sh | bash)" >> $GITHUB_ENV
- name: Meilisearch (${{ env.MEILISEARCH_VERSION }}) setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} meilisearch --master-key=masterKey --no-analytics
- name: Run test suite - default HTTP client (Guzzle 7)
run: |
sh scripts/tests.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Expand Up @@ -60,7 +60,7 @@ jobs:
composer remove --dev friendsofphp/php-cs-fixer --no-update --no-interaction
composer update --prefer-dist --no-progress
- name: Meilisearch (latest version) setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics
- name: Run test suite - default HTTP client (Guzzle 7)
run: |
sh scripts/tests.sh
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -215,7 +215,7 @@ $index->search(

## 🤖 Compatibility with Meilisearch

This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0).
This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).

## 💡 Learn More

Expand Down
1 change: 1 addition & 0 deletions src/Contracts/Index/Settings.php
Expand Up @@ -11,6 +11,7 @@ class Settings extends Data implements \JsonSerializable
public function __construct(array $data = [])
{
$data['synonyms'] = new Synonyms($data['synonyms'] ?? []);
$data['typoTolerance'] = new TypoTolerance($data['typoTolerance'] ?? []);
parent::__construct($data);
}

Expand Down
15 changes: 15 additions & 0 deletions src/Contracts/Index/TypoTolerance.php
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Contracts\Index;

use MeiliSearch\Contracts\Data;

class TypoTolerance extends Data implements \JsonSerializable
{
public function jsonSerialize(): object
{
return (object) $this->getIterator()->getArrayCopy();
}
}
19 changes: 19 additions & 0 deletions src/Endpoints/Delegates/HandlesSettings.php
Expand Up @@ -5,6 +5,7 @@
namespace MeiliSearch\Endpoints\Delegates;

use MeiliSearch\Contracts\Index\Synonyms;
use MeiliSearch\Contracts\Index\TypoTolerance;

trait HandlesSettings
{
Expand Down Expand Up @@ -144,4 +145,22 @@ public function resetSortableAttributes(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/sortable-attributes');
}

// Settings - Typo Tolerance

public function getTypoTolerance(): array
{
return (new TypoTolerance($this->http->get(self::PATH.'/'.$this->uid.'/settings/typo-tolerance')))
->getIterator()->getArrayCopy();
}

public function updateTypoTolerance(array $typoTolerance): array
{
return $this->http->post(self::PATH.'/'.$this->uid.'/settings/typo-tolerance', new TypoTolerance($typoTolerance));
}

public function resetTypoTolerance(): array
{
return $this->http->delete(self::PATH.'/'.$this->uid.'/settings/typo-tolerance');
}
}
2 changes: 2 additions & 0 deletions tests/Endpoints/IndexTest.php
Expand Up @@ -35,6 +35,8 @@ public function testIndexSettingsAlwaysReturnArrays(): void
$this->assertIsArray($this->index->getFilterableAttributes());
/* @phpstan-ignore-next-line */
$this->assertIsArray($this->index->getDisplayedAttributes());
/* @phpstan-ignore-next-line */
$this->assertIsArray($this->index->getTypoTolerance());
}

public function testGetPrimaryKey(): void
Expand Down
114 changes: 104 additions & 10 deletions tests/Endpoints/SearchTest.php
Expand Up @@ -139,6 +139,100 @@ public function testExceptionIfNoIndexWhenSearching(): void
$index->search('prince');
}

public function testParametersCropMarker(): void
{
$response = $this->index->search('blood', [
'limit' => 1,
'attributesToCrop' => ['title'],
'cropLength' => 2,
]);

$this->assertArrayHasKey('_formatted', $response->getHit(0));
$this->assertSame('…Half-Blood…', $response->getHit(0)['_formatted']['title']);

$response = $this->index->search('blood', [
'limit' => 1,
'attributesToCrop' => ['title'],
'cropLength' => 2,
], [
'raw' => true,
]);

$this->assertArrayHasKey('_formatted', $response['hits'][0]);
$this->assertSame('…Half-Blood…', $response['hits'][0]['_formatted']['title']);
}

public function testParametersWithCustomizedCropMarker(): void
{
$response = $this->index->search('blood', [
'limit' => 1,
'attributesToCrop' => ['title'],
'cropLength' => 3,
'cropMarker' => '(ꈍᴗꈍ)',
]);

$this->assertArrayHasKey('_formatted', $response->getHit(0));
$this->assertSame('(ꈍᴗꈍ)Half-Blood Prince', $response->getHit(0)['_formatted']['title']);

$response = $this->index->search('blood', [
'limit' => 1,
'attributesToCrop' => ['title'],
'cropLength' => 3,
'cropMarker' => '(ꈍᴗꈍ)',
], [
'raw' => true,
]);

$this->assertArrayHasKey('_formatted', $response['hits'][0]);
$this->assertSame('(ꈍᴗꈍ)Half-Blood Prince', $response['hits'][0]['_formatted']['title']);
}

public function testParametersWithHighlightTag(): void
{
$response = $this->index->search('and', [
'limit' => 1,
'attributesToHighlight' => ['*'],
]);

$this->assertArrayHasKey('_formatted', $response->getHit(0));
$this->assertSame('Pride <em>and</em> Prejudice', $response->getHit(0)['_formatted']['title']);

$response = $this->index->search('and', [
'limit' => 1,
'attributesToHighlight' => ['*'],
], [
'raw' => true,
]);

$this->assertArrayHasKey('_formatted', $response['hits'][0]);
$this->assertSame('Pride <em>and</em> Prejudice', $response['hits'][0]['_formatted']['title']);
}

public function testParametersWithCustomizedHighlightTag(): void
{
$response = $this->index->search('and', [
'limit' => 1,
'attributesToHighlight' => ['*'],
'highlightPreTag' => '(⊃。•́‿•̀。)⊃ ',
'highlightPostTag' => ' ⊂(´• ω •`⊂)',
]);

$this->assertArrayHasKey('_formatted', $response->getHit(0));
$this->assertSame('Pride (⊃。•́‿•̀。)⊃ and ⊂(´• ω •`⊂) Prejudice', $response->getHit(0)['_formatted']['title']);

$response = $this->index->search('and', [
'limit' => 1,
'attributesToHighlight' => ['*'],
'highlightPreTag' => '(⊃。•́‿•̀。)⊃ ',
'highlightPostTag' => ' ⊂(´• ω •`⊂)',
], [
'raw' => true,
]);

$this->assertArrayHasKey('_formatted', $response['hits'][0]);
$this->assertSame('Pride (⊃。•́‿•̀。)⊃ and ⊂(´• ω •`⊂) Prejudice', $response['hits'][0]['_formatted']['title']);
}

public function testParametersArray(): void
{
$response = $this->index->updateFilterableAttributes(['title']);
Expand All @@ -160,7 +254,7 @@ public function testParametersArray(): void
$this->assertArrayHasKey('_formatted', $response->getHit(0));
$this->assertArrayNotHasKey('comment', $response->getHit(0));
$this->assertArrayNotHasKey('comment', $response->getHit(0)['_matchesInfo']);
$this->assertSame('Petit <em>Prince</em>', $response->getHit(0)['_formatted']['title']);
$this->assertSame('Le Petit <em>Prince</em>', $response->getHit(0)['_formatted']['title']);

$response = $this->index->search('prince', [
'limit' => 5,
Expand All @@ -180,7 +274,7 @@ public function testParametersArray(): void
$this->assertArrayHasKey('_formatted', $response['hits'][0]);
$this->assertArrayNotHasKey('comment', $response['hits'][0]);
$this->assertArrayNotHasKey('comment', $response['hits'][0]['_matchesInfo']);
$this->assertSame('Petit <em>Prince</em>', $response['hits'][0]['_formatted']['title']);
$this->assertSame('Le Petit <em>Prince</em>', $response['hits'][0]['_formatted']['title']);
}

public function testParametersCanBeAStar(): void
Expand All @@ -204,7 +298,7 @@ public function testParametersCanBeAStar(): void
$this->assertArrayHasKey('_formatted', $response->getHit(0));
$this->assertArrayHasKey('comment', $response->getHit(0));
$this->assertArrayNotHasKey('comment', $response->getHit(0)['_matchesInfo']);
$this->assertSame('Petit <em>Prince</em>', $response->getHit(0)['_formatted']['title']);
$this->assertSame('Le Petit <em>Prince</em>', $response->getHit(0)['_formatted']['title']);

$response = $this->index->search('prince', [
'limit' => 5,
Expand All @@ -224,7 +318,7 @@ public function testParametersCanBeAStar(): void
$this->assertArrayHasKey('_formatted', $response['hits'][0]);
$this->assertArrayHasKey('comment', $response['hits'][0]);
$this->assertArrayNotHasKey('comment', $response['hits'][0]['_matchesInfo']);
$this->assertSame('Petit <em>Prince</em>', $response['hits'][0]['_formatted']['title']);
$this->assertSame('Le Petit <em>Prince</em>', $response['hits'][0]['_formatted']['title']);
}

public function testSearchWithFilterCanBeInt(): void
Expand Down Expand Up @@ -613,16 +707,16 @@ public function testBasicSearchWithFacetsOptionAndMultipleFacets(): void
$this->index->waitForTask($response['uid']);

$response = $this->index->search(
'prince',
'witch',
['facetsDistribution' => ['genre', 'adaptation']]
);

$this->assertCount(2, $response->getFacetsDistribution()['genre']);
$this->assertCount(1, $response->getFacetsDistribution()['genre']);
$this->assertEquals(1, $response->getFacetsDistribution()['genre']['adventure']);
$this->assertEquals(1, $response->getFacetsDistribution()['genre']['fantasy']);
$this->assertEquals([], $response->getFacetsDistribution()['adaptation']);
$this->assertCount(0, $response->getRaw()['facetsDistribution']['adaptation']);
$this->assertCount(2, $response->getRaw()['facetsDistribution']['genre']);
$this->assertCount(1, $response->getFacetsDistribution()['adaptation']);
$this->assertEquals(1, $response->getFacetsDistribution()['adaptation']['video game']);
$this->assertCount(1, $response->getRaw()['facetsDistribution']['adaptation']);
$this->assertCount(1, $response->getRaw()['facetsDistribution']['genre']);
$this->assertEquals($response->getRaw()['hits'], $response->getHits());
$this->assertEquals($response->getRaw()['facetsDistribution'], $response->getFacetsDistribution());
}
Expand Down

0 comments on commit 57303fa

Please sign in to comment.