Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
47616117
Commit
47616117
authored
Apr 10, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #521
parents
80dd7835
4b54760a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
362 additions
and
0 deletions
+362
-0
enumeration-classes.txt
docs/reference/enumeration-classes.txt
+3
-0
MongoDBModelIndexInfo-is2dSphere.txt
docs/reference/method/MongoDBModelIndexInfo-is2dSphere.txt
+59
-0
MongoDBModelIndexInfo-isGeoHaystack.txt
.../reference/method/MongoDBModelIndexInfo-isGeoHaystack.txt
+59
-0
MongoDBModelIndexInfo-isText.txt
docs/reference/method/MongoDBModelIndexInfo-isText.txt
+58
-0
IndexInfo.php
src/Model/IndexInfo.php
+30
-0
IndexInfoFunctionalTest.php
tests/Model/IndexInfoFunctionalTest.php
+78
-0
IndexInfoTest.php
tests/Model/IndexInfoTest.php
+75
-0
No files found.
docs/reference/enumeration-classes.txt
View file @
47616117
...
@@ -134,7 +134,10 @@ Methods
...
@@ -134,7 +134,10 @@ Methods
/reference/method/MongoDBModelIndexInfo-getName
/reference/method/MongoDBModelIndexInfo-getName
/reference/method/MongoDBModelIndexInfo-getNamespace
/reference/method/MongoDBModelIndexInfo-getNamespace
/reference/method/MongoDBModelIndexInfo-getVersion
/reference/method/MongoDBModelIndexInfo-getVersion
/reference/method/MongoDBModelIndexInfo-is2dSphere
/reference/method/MongoDBModelIndexInfo-isGeoHaystack
/reference/method/MongoDBModelIndexInfo-isSparse
/reference/method/MongoDBModelIndexInfo-isSparse
/reference/method/MongoDBModelIndexInfo-isText
/reference/method/MongoDBModelIndexInfo-isTtl
/reference/method/MongoDBModelIndexInfo-isTtl
/reference/method/MongoDBModelIndexInfo-isUnique
/reference/method/MongoDBModelIndexInfo-isUnique
...
...
docs/reference/method/MongoDBModelIndexInfo-is2dSphere.txt
0 → 100644
View file @
47616117
=======================================
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
docs/reference/method/MongoDBModelIndexInfo-isGeoHaystack.txt
0 → 100644
View file @
47616117
==========================================
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
docs/reference/method/MongoDBModelIndexInfo-isText.txt
0 → 100644
View file @
47616117
===================================
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
src/Model/IndexInfo.php
View file @
47616117
...
@@ -110,6 +110,26 @@ class IndexInfo implements ArrayAccess
...
@@ -110,6 +110,26 @@ class IndexInfo implements ArrayAccess
return
(
integer
)
$this
->
info
[
'v'
];
return
(
integer
)
$this
->
info
[
'v'
];
}
}
/**
* Return whether or not this index is of type 2dsphere.
*
* @return boolean
*/
public
function
is2dSphere
()
{
return
array_search
(
'2dsphere'
,
$this
->
getKey
(),
true
)
!==
false
;
}
/**
* Return whether or not this index is of type geoHaystack.
*
* @return boolean
*/
public
function
isGeoHaystack
()
{
return
array_search
(
'geoHaystack'
,
$this
->
getKey
(),
true
)
!==
false
;
}
/**
/**
* Return whether this is a sparse index.
* Return whether this is a sparse index.
*
*
...
@@ -121,6 +141,16 @@ class IndexInfo implements ArrayAccess
...
@@ -121,6 +141,16 @@ class IndexInfo implements ArrayAccess
return
!
empty
(
$this
->
info
[
'sparse'
]);
return
!
empty
(
$this
->
info
[
'sparse'
]);
}
}
/**
* Return whether or not this index is of type text.
*
* @return boolean
*/
public
function
isText
()
{
return
array_search
(
'text'
,
$this
->
getKey
(),
true
)
!==
false
;
}
/**
/**
* Return whether this is a TTL index.
* Return whether this is a TTL index.
*
*
...
...
tests/Model/IndexInfoFunctionalTest.php
0 → 100644
View file @
47616117
<?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
());
$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'
]);
}
}
tests/Model/IndexInfoTest.php
View file @
47616117
...
@@ -21,7 +21,10 @@ class IndexInfoTest extends TestCase
...
@@ -21,7 +21,10 @@ class IndexInfoTest extends TestCase
$this
->
assertSame
([
'x'
=>
1
],
$info
->
getKey
());
$this
->
assertSame
([
'x'
=>
1
],
$info
->
getKey
());
$this
->
assertSame
(
'x_1'
,
$info
->
getName
());
$this
->
assertSame
(
'x_1'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
is2dSphere
());
$this
->
assertFalse
(
$info
->
isGeoHaystack
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isText
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isUnique
());
$this
->
assertFalse
(
$info
->
isUnique
());
}
}
...
@@ -40,7 +43,10 @@ class IndexInfoTest extends TestCase
...
@@ -40,7 +43,10 @@ class IndexInfoTest extends TestCase
$this
->
assertSame
([
'y'
=>
1
],
$info
->
getKey
());
$this
->
assertSame
([
'y'
=>
1
],
$info
->
getKey
());
$this
->
assertSame
(
'y_sparse'
,
$info
->
getName
());
$this
->
assertSame
(
'y_sparse'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
is2dSphere
());
$this
->
assertFalse
(
$info
->
isGeoHaystack
());
$this
->
assertTrue
(
$info
->
isSparse
());
$this
->
assertTrue
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isText
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isUnique
());
$this
->
assertFalse
(
$info
->
isUnique
());
}
}
...
@@ -59,7 +65,10 @@ class IndexInfoTest extends TestCase
...
@@ -59,7 +65,10 @@ class IndexInfoTest extends TestCase
$this
->
assertSame
([
'z'
=>
1
],
$info
->
getKey
());
$this
->
assertSame
([
'z'
=>
1
],
$info
->
getKey
());
$this
->
assertSame
(
'z_unique'
,
$info
->
getName
());
$this
->
assertSame
(
'z_unique'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
is2dSphere
());
$this
->
assertFalse
(
$info
->
isGeoHaystack
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isText
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertTrue
(
$info
->
isUnique
());
$this
->
assertTrue
(
$info
->
isUnique
());
}
}
...
@@ -78,7 +87,10 @@ class IndexInfoTest extends TestCase
...
@@ -78,7 +87,10 @@ class IndexInfoTest extends TestCase
$this
->
assertSame
([
'z'
=>
1
],
$info
->
getKey
());
$this
->
assertSame
([
'z'
=>
1
],
$info
->
getKey
());
$this
->
assertSame
(
'z_unique'
,
$info
->
getName
());
$this
->
assertSame
(
'z_unique'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
is2dSphere
());
$this
->
assertFalse
(
$info
->
isGeoHaystack
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isText
());
$this
->
assertTrue
(
$info
->
isTtl
());
$this
->
assertTrue
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isUnique
());
$this
->
assertFalse
(
$info
->
isUnique
());
$this
->
assertArrayHasKey
(
'expireAfterSeconds'
,
$info
);
$this
->
assertArrayHasKey
(
'expireAfterSeconds'
,
$info
);
...
@@ -139,4 +151,67 @@ class IndexInfoTest extends TestCase
...
@@ -139,4 +151,67 @@ class IndexInfoTest extends TestCase
$this
->
expectExceptionMessage
(
'MongoDB\Model\IndexInfo is immutable'
);
$this
->
expectExceptionMessage
(
'MongoDB\Model\IndexInfo is immutable'
);
unset
(
$info
[
'v'
]);
unset
(
$info
[
'v'
]);
}
}
public
function
testIs2dSphere
()
{
$info
=
new
IndexInfo
([
'v'
=>
2
,
'key'
=>
[
'pos'
=>
'2dsphere'
],
'name'
=>
'pos_2dsphere'
,
'ns'
=>
'foo.bar'
,
]);
$this
->
assertSame
(
2
,
$info
->
getVersion
());
$this
->
assertSame
([
'pos'
=>
'2dsphere'
],
$info
->
getKey
());
$this
->
assertSame
(
'pos_2dsphere'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertTrue
(
$info
->
is2dSphere
());
$this
->
assertFalse
(
$info
->
isGeoHaystack
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isText
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isUnique
());
}
public
function
testIsGeoHaystack
()
{
$info
=
new
IndexInfo
([
'v'
=>
2
,
'key'
=>
[
'pos2'
=>
'geoHaystack'
,
'x'
=>
1
],
'name'
=>
'pos2_geoHaystack_x_1'
,
'ns'
=>
'foo.bar'
,
]);
$this
->
assertSame
(
2
,
$info
->
getVersion
());
$this
->
assertSame
([
'pos2'
=>
'geoHaystack'
,
'x'
=>
1
],
$info
->
getKey
());
$this
->
assertSame
(
'pos2_geoHaystack_x_1'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
is2dSphere
());
$this
->
assertTrue
(
$info
->
isGeoHaystack
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isText
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isUnique
());
}
public
function
testIsText
()
{
$info
=
new
IndexInfo
([
'v'
=>
2
,
'key'
=>
[
'_fts'
=>
'text'
,
'_ftsx'
=>
1
],
'name'
=>
'title_text_description_text'
,
'ns'
=>
'foo.bar'
,
]);
$this
->
assertSame
(
2
,
$info
->
getVersion
());
$this
->
assertSame
([
'_fts'
=>
'text'
,
'_ftsx'
=>
1
],
$info
->
getKey
());
$this
->
assertSame
(
'title_text_description_text'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
is2dSphere
());
$this
->
assertFalse
(
$info
->
isGeoHaystack
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertTrue
(
$info
->
isText
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isUnique
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment