Skip to content

Commit 62ba594

Browse files
feat[indexes]: base implementation for 'inverted' index
1 parent 95d9089 commit 62ba594

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/Collection/Index/Factory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public static function factory(array $attributes): IndexInterface
3838
'geo' => GeoSpatialIndex::class,
3939
'skiplist' => SkipListIndex::class,
4040
'ttl' => TTLIndex::class,
41+
'inverted' => InvertedIndex::class
4142
];
4243

4344
if (!array_key_exists($attributes['type'], $indexes)) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace ArangoDB\Collection\Index;
4+
5+
use ArangoDB\Validation\Exceptions\InvalidParameterException;
6+
7+
/**
8+
* Inverted index representation
9+
*
10+
* @package ArangoDB\Collection\Index
11+
* @author Lucas S. Vieira
12+
*/
13+
class InvertedIndex extends Index
14+
{
15+
/**
16+
* InvertedIndex constructor
17+
*
18+
* @param array $fields Fields for which the index applies to
19+
* @param array $attributes Index $attributes
20+
*
21+
* @throws InvalidParameterException
22+
*/
23+
public function __construct(array $fields, array $attributes = [])
24+
{
25+
parent::__construct('inverted', $fields, $attributes);
26+
}
27+
}

tests/Collection/Index/FactoryTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Unit\Collection\GeneralIndex;
44

5+
use ArangoDB\Collection\Index\InvertedIndex;
56
use Unit\TestCase;
67
use ArangoDB\Collection\Index\Index;
78
use ArangoDB\Collection\Index\Factory;
@@ -161,6 +162,21 @@ public function mockGenericArray(): array
161162
];
162163
}
163164

165+
public function mockInvertedArray(): array
166+
{
167+
return [
168+
'fields' => [
169+
'my_field',
170+
],
171+
'id' => 'coll/0',
172+
'name' => 'inverted_idx',
173+
'sparse' => true,
174+
'unique' => false,
175+
'type' => 'inverted',
176+
'selectivityEstimate' => 0.015
177+
];
178+
}
179+
164180
public function testFactoryMakesPrimaryIndex()
165181
{
166182
$index = Factory::factory($this->mockPrimaryArray());
@@ -209,6 +225,12 @@ public function testFactoryMakesTTLIndex()
209225
$this->assertInstanceOf(TTLIndex::class, $index);
210226
}
211227

228+
public function testFactoryMakesInvertedIndex()
229+
{
230+
$index = Factory::factory($this->mockInvertedArray());
231+
$this->assertInstanceOf(InvertedIndex::class, $index);
232+
}
233+
212234
public function testFactoryMakesGenericIndex()
213235
{
214236
$this->expectException(IndexException::class);

0 commit comments

Comments
 (0)