Skip to content

Commit 4d6016e

Browse files
committed
Created getIndex() method in CollectionsHandler.
1 parent f7bb47e commit 4d6016e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/triagens/ArangoDb/CollectionHandler.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,21 @@ public function index($collectionId, $type = "", $attributes = array(), $unique
585585
return $result;
586586
}
587587

588+
/**
589+
* Get the information about an index in a collection
590+
* @param string $collection - the id of the collection
591+
* @param string $indexId - the id of the index
592+
* @return array
593+
*/
594+
public function getIndex($collection, $indexId)
595+
{
596+
$url = UrlHelper::buildUrl(Urls::URL_INDEX, $collection, $indexId);
597+
$response = $this->getConnection()->get($url);
598+
599+
$data = $response->getJson();
600+
601+
return $data;
602+
}
588603

589604
/**
590605
* Get indexes of a collection

tests/CollectionBasicTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,24 @@ public function testCreateSkipListIndex()
386386
$this->assertEquals(true, $indexInfo[CollectionHandler::OPTION_UNIQUE], 'unique was not set to true!');
387387
}
388388

389+
/**
390+
* Test creating an index and getting it to verify.
391+
*/
392+
public function testGetIndex()
393+
{
394+
$result = $this->collectionHandler->createFulltextIndex('ArangoDB_PHP_TestSuite_IndexTestCollection', array('testGetIndexField'), 100);
395+
396+
//Parse for the index's key
397+
$key = str_replace('ArangoDB_PHP_TestSuite_IndexTestCollection/', "", $result['id']);
398+
399+
$indexInfo = $this->collectionHandler->getIndex('ArangoDB_PHP_TestSuite_IndexTestCollection', $key);
400+
401+
$this->assertEquals(CollectionHandler::OPTION_FULLTEXT_INDEX, $indexInfo[CollectionHandler::OPTION_TYPE], "Index type does not match!");
402+
$this->assertCount(1, $indexInfo['fields'], "There should only be 1 indexed field!");
403+
$this->assertEquals("testGetIndexField", $indexInfo['fields'][0], "Index field does not match!");
404+
$this->assertEquals(100, $indexInfo[CollectionHandler::OPTION_MIN_LENGTH], 'Minlength does not match!');
405+
}
406+
389407
public function tearDown()
390408
{
391409

0 commit comments

Comments
 (0)