-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-80: Add IndexInfo helper methods for special index type options #521
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| ======================================= | ||
| MongoDB\\Model\\IndexInfo::is2dSphere() | ||
| ======================================= | ||
|
|
||
| .. versionadded:: 1.4 | ||
|
|
||
| .. default-domain:: mongodb | ||
|
|
||
| .. contents:: On this page | ||
| :local: | ||
| :backlinks: none | ||
| :depth: 1 | ||
| :class: singlecol | ||
|
|
||
| Definition | ||
| ---------- | ||
|
|
||
| .. phpmethod:: MongoDB\\Model\\IndexInfo::is2dSphere() | ||
|
|
||
| Return whether the index is a :manual:`2dsphere </core/2dsphere>` | ||
| index. | ||
|
|
||
| .. code-block:: php | ||
|
|
||
| function is2dSphere(): boolean | ||
|
|
||
| Return Values | ||
| ------------- | ||
|
|
||
| A boolean indicating whether the index is a 2dsphere index. | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
||
| .. code-block:: php | ||
|
|
||
| <?php | ||
|
|
||
| $collection = (new MongoDB\Client)->selectCollection('test', 'places'); | ||
|
|
||
| $collection->createIndex(['pos' => '2dsphere']); | ||
|
|
||
| foreach ($collection->listIndexes() as $index) { | ||
| if ($index->is2dSphere()) { | ||
| printf("%s has 2dsphereIndexVersion: %d\n", $index->getName(), $index['2dsphereIndexVersion']); | ||
| } | ||
| } | ||
|
|
||
| The output would then resemble:: | ||
|
|
||
| pos_2dsphere has 2dsphereIndexVersion: 3 | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
||
| - :phpmethod:`MongoDB\\Collection::createIndex()` | ||
| - :phpmethod:`MongoDB\\Collection::listIndexes()` | ||
| - :manual:`2dsphere Indexes </core/2dsphere>` reference in the MongoDB | ||
| manual |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| ========================================== | ||
| MongoDB\\Model\\IndexInfo::isGeoHaystack() | ||
| ========================================== | ||
|
|
||
| .. versionadded:: 1.4 | ||
|
|
||
| .. default-domain:: mongodb | ||
|
|
||
| .. contents:: On this page | ||
| :local: | ||
| :backlinks: none | ||
| :depth: 1 | ||
| :class: singlecol | ||
|
|
||
| Definition | ||
| ---------- | ||
|
|
||
| .. phpmethod:: MongoDB\\Model\\IndexInfo::isGeoHaystack() | ||
|
|
||
| Return whether the index is a :manual:`geoHaystack | ||
| </core/geohaystack>` index. | ||
|
|
||
| .. code-block:: php | ||
|
|
||
| function isGeoHaystack(): boolean | ||
|
|
||
| Return Values | ||
| ------------- | ||
|
|
||
| A boolean indicating whether the index is a geoHaystack index. | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
||
| .. code-block:: php | ||
|
|
||
| <?php | ||
|
|
||
| $collection = (new MongoDB\Client)->selectCollection('test', 'places'); | ||
|
|
||
| $collection->createIndex(['pos' => 'geoHaystack', 'x' => 1], ['bucketSize' => 5]); | ||
|
|
||
| foreach ($collection->listIndexes() as $index) { | ||
| if ($index->isGeoHaystack()) { | ||
| printf("%s has bucketSize: %d\n", $index->getName(), $index['bucketSize']); | ||
| } | ||
| } | ||
|
|
||
| The output would then resemble:: | ||
|
|
||
| pos_geoHaystack_x_1 has bucketSize: 5 | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
||
| - :phpmethod:`MongoDB\\Collection::createIndex()` | ||
| - :phpmethod:`MongoDB\\Collection::listIndexes()` | ||
| - :manual:`geoHaystack Indexes </core/geohaystack>` reference in the MongoDB | ||
| manual |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| =================================== | ||
| MongoDB\\Model\\IndexInfo::isText() | ||
| =================================== | ||
|
|
||
| .. versionadded:: 1.4 | ||
|
|
||
| .. default-domain:: mongodb | ||
|
|
||
| .. contents:: On this page | ||
| :local: | ||
| :backlinks: none | ||
| :depth: 1 | ||
| :class: singlecol | ||
|
|
||
| Definition | ||
| ---------- | ||
|
|
||
| .. phpmethod:: MongoDB\\Model\\IndexInfo::isText() | ||
|
|
||
| Return whether the index is a :manual:`text </core/index-text>` index. | ||
|
|
||
| .. code-block:: php | ||
|
|
||
| function isText(): boolean | ||
|
|
||
| Return Values | ||
| ------------- | ||
|
|
||
| A boolean indicating whether the index is a text index. | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
||
| .. code-block:: php | ||
|
|
||
| <?php | ||
|
|
||
| $collection = (new MongoDB\Client)->selectCollection('test', 'restaurants'); | ||
|
|
||
| $collection->createIndex(['name' => 'text']); | ||
|
|
||
| foreach ($collection->listIndexes() as $index) { | ||
| if ($index->isText()) { | ||
| printf("%s has default language: %d\n", $index->getName(), $index['default_language']); | ||
| } | ||
| } | ||
|
|
||
| The output would then resemble:: | ||
|
|
||
| name_text has default language: english | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
||
| - :phpmethod:`MongoDB\\Collection::createIndex()` | ||
| - :phpmethod:`MongoDB\\Collection::listIndexes()` | ||
| - :manual:`Text Indexes </core/index-text>` reference in the MongoDB | ||
| manual | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
|
|
||
| namespace MongoDB\Tests\Model; | ||
|
|
||
| use MongoDB\Collection; | ||
| use MongoDB\Tests\FunctionalTestCase; | ||
|
|
||
| class IndexInfoFunctionalTest extends FunctionalTestCase | ||
| { | ||
| private $collection; | ||
|
|
||
| public function setUp() | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| $this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're creating a collection in each test, let's drop it upon I see no reason we can't use the Collection methods, so |
||
| $this->collection->drop(); | ||
| } | ||
|
|
||
| public function tearDown() | ||
| { | ||
| if ($this->hasFailed()) { | ||
| return; | ||
| } | ||
|
|
||
| $this->collection->drop(); | ||
| } | ||
|
|
||
| public function testIs2dSphere() | ||
| { | ||
| $indexName = $this->collection->createIndex(['pos' => '2dsphere']); | ||
| $result = $this->collection->listIndexes(); | ||
|
|
||
| $result->rewind(); | ||
| $result->next(); | ||
| $index = $result->current(); | ||
|
|
||
| $this->assertEquals($indexName, $index->getName()); | ||
| $this->assertTrue($index->is2dSphere()); | ||
|
|
||
| $expectedVersion = version_compare($this->getServerVersion(), '3.2.0', '<') ? 2 : 3; | ||
| $this->assertEquals($expectedVersion, $index['2dsphereIndexVersion']); | ||
| } | ||
|
|
||
| public function testIsGeoHaystack() | ||
| { | ||
| $indexName = $this->collection->createIndex(['pos' => 'geoHaystack', 'x' => 1], ['bucketSize' => 5]); | ||
| $result = $this->collection->listIndexes(); | ||
|
|
||
| $result->rewind(); | ||
| $result->next(); | ||
| $index = $result->current(); | ||
|
|
||
| $this->assertEquals($indexName, $index->getName()); | ||
| $this->assertTrue($index->isGeoHaystack()); | ||
| $this->assertEquals(5, $index['bucketSize']); | ||
| } | ||
|
|
||
| public function testIsText() | ||
| { | ||
| $indexName = $this->collection->createIndex(['x' => 'text']); | ||
| $result = $this->collection->listIndexes(); | ||
|
|
||
| $result->rewind(); | ||
| $result->next(); | ||
| $index = $result->current(); | ||
|
|
||
| $this->assertEquals($indexName, $index->getName()); | ||
| $this->assertTrue($index->isText()); | ||
| $this->assertEquals('english', $index['default_language']); | ||
| $this->assertEquals('language', $index['language_override']); | ||
|
|
||
| $expectedVersion = version_compare($this->getServerVersion(), '3.2.0', '<') ? 2 : 3; | ||
| $this->assertEquals($expectedVersion, $index['textIndexVersion']); | ||
|
|
||
| $this->assertSameDocument(['x' => 1], $index['weights']); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline after.