Skip to content

Added _id in path_by_field method #141

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

Merged
merged 1 commit into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,25 @@ jobs:
composer update -n --prefer-dist
php vendor/bin/phpunit

php81:
docker:
- image: cimg/php:8.1

working_directory: ~/project
steps:
- checkout
- run:
name: Run tests
command: |
composer update -n --prefer-dist
php vendor/bin/phpunit

workflows:
version: 2
test:
jobs:
- php72
- php73
- php74
- php80
- php80
- php81
4 changes: 4 additions & 0 deletions Model/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,10 @@ public static function createFromArray(array $array): self
*/
public static function getPathByField(string $field)
{
if ('_id' === $field) {
return $field;
}

return in_array($field, ['id', 'type'])
? 'uuid.'.$field
: 'indexed_metadata.'.$field;
Expand Down
12 changes: 12 additions & 0 deletions Tests/Model/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,16 @@ public function testMap()
$this->assertEquals(10, $item->getScore());
$this->assertNull($item->getCoordinate());
}

/**
* @return void
*/
public function testPathByField()
{
$this->assertEquals('_id', Item::getPathByField('_id'));
$this->assertEquals('uuid.id', Item::getPathByField('id'));
$this->assertEquals('uuid.type', Item::getPathByField('type'));
$this->assertEquals('indexed_metadata.another_id', Item::getPathByField('another_id'));
$this->assertEquals('indexed_metadata._field', Item::getPathByField('_field'));
}
}