forked from biblioverse/biblioteca
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
238 additions
and
35 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
BibliotecaTypesenseBundle/src/Mapper/CollectionOptions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Biblioteca\TypesenseBundle\Mapper; | ||
|
||
class CollectionOptions implements CollectionOptionsInterface | ||
{ | ||
public function __construct( | ||
public ?string $tokenSeparators = null, | ||
public ?string $symbolsToIndex = null, | ||
public ?string $defaultSortingField = null, | ||
) { | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'token_separators' => $this->tokenSeparators, | ||
'symbols_to_index' => $this->symbolsToIndex, | ||
'default_sorting_field' => $this->defaultSortingField, | ||
]; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
BibliotecaTypesenseBundle/src/Mapper/CollectionOptionsInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Biblioteca\TypesenseBundle\Mapper; | ||
|
||
interface CollectionOptionsInterface | ||
{ | ||
public function toArray(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Biblioteca\TypesenseBundle\Mapper; | ||
|
||
use Biblioteca\TypesenseBundle\Type\DataTypeEnum; | ||
|
||
class FieldMapping implements FieldMappingInterface | ||
{ | ||
public string $type; | ||
|
||
public function __construct( | ||
public string $name, | ||
DataTypeEnum|string $type, | ||
public ?bool $facet = null, | ||
public ?bool $optional = null, | ||
public ?bool $drop = null, | ||
public ?bool $index = null, | ||
public ?bool $infix = null, | ||
public ?bool $range_index = null, | ||
public ?bool $sort = null, // Default depends on the type; not assigned here | ||
public ?bool $stem = null, | ||
public ?bool $store = null, | ||
public ?int $num_dim = null, | ||
public ?string $locale = null, | ||
public ?string $reference = null, | ||
public ?string $vec_dist = null, | ||
) { | ||
$this->type = $type instanceof DataTypeEnum ? $type->value : $type; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return array_filter([ | ||
'name' => $this->name, | ||
'type' => $this->type, | ||
'facet' => $this->facet, | ||
'optional' => $this->optional, | ||
'index' => $this->index, | ||
'store' => $this->store, | ||
'sort' => $this->sort, | ||
'infix' => $this->infix, | ||
'locale' => $this->locale, | ||
'num_dim' => $this->num_dim, | ||
'vec_dist' => $this->vec_dist, | ||
'reference' => $this->reference, | ||
'range_index' => $this->range_index, | ||
'drop' => $this->drop, | ||
'stem' => $this->stem, | ||
]); | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
BibliotecaTypesenseBundle/src/Mapper/FieldMappingInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Biblioteca\TypesenseBundle\Mapper; | ||
|
||
use Biblioteca\TypesenseBundle\Type\DataTypeEnum; | ||
|
||
interface FieldMappingInterface | ||
{ | ||
/** | ||
* Field options and value | ||
* @return array<string,mixed> | ||
*/ | ||
public function toArray(): array; | ||
|
||
/** | ||
* @see DataTypeEnum | ||
* @return string | ||
*/ | ||
public function getType(): string; | ||
|
||
public function getName(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Biblioteca\TypesenseBundle\Mapper; | ||
|
||
interface MappingInterface | ||
{ | ||
/** | ||
* @return FieldMappingInterface[] | ||
*/ | ||
public function getFields(): array; | ||
|
||
public function getName(): string; | ||
|
||
public function getCollectionOptions(): ?CollectionOptionsInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Biblioteca\TypesenseBundle\Type; | ||
|
||
enum DataTypeEnum: string | ||
{ | ||
case PRIMARY = 'primary'; | ||
case STRING = 'string'; | ||
case STRING_ARRAY = 'string[]'; | ||
case INT32 = 'int32'; | ||
case INT32_ARRAY = 'int32[]'; | ||
case INT64 = 'int64'; | ||
case INT64_ARRAY = 'int64[]'; | ||
case FLOAT = 'float'; | ||
case FLOAT_ARRAY = 'float[]'; | ||
case BOOL = 'bool'; | ||
case BOOL_ARRAY = 'bool[]'; | ||
case GEOPOINT = 'geopoint'; | ||
case GEOPOINT_ARRAY = 'geopoint[]'; | ||
case OBJECT = 'object'; | ||
case OBJECT_ARRAY = 'object[]'; | ||
case STRING_CONVERTIBLE = 'string*'; | ||
case IMAGE = 'image'; | ||
case AUTO = 'auto'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters