2022-06-08 17:05:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Jenssegers\Mongodb\Eloquent\Model;
|
|
|
|
use Typesense\LaravelTypesense\Interfaces\TypesenseDocument;
|
|
|
|
|
|
|
|
abstract class JikanApiSearchableModel extends JikanApiModel implements TypesenseDocument
|
|
|
|
{
|
|
|
|
use JikanSearchable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public abstract function typesenseQueryBy(): array;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Typesense schema to be created.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getCollectionSchema(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'name' => $this->searchableAs(),
|
|
|
|
'fields' => [
|
|
|
|
[
|
|
|
|
'name' => '.*',
|
|
|
|
'type' => 'auto',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the name of the index associated with the model.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function searchableAs(): string
|
|
|
|
{
|
|
|
|
return strtolower($this->table) . '_index';
|
|
|
|
}
|
2022-06-08 17:17:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value used to index the model.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getScoutKey(): mixed
|
|
|
|
{
|
|
|
|
return $this->mal_id;
|
|
|
|
}
|
2022-06-17 16:23:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the key name used to index the model.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getScoutKeyName(): mixed
|
|
|
|
{
|
|
|
|
return 'mal_id';
|
|
|
|
}
|
2022-06-08 17:05:12 +01:00
|
|
|
}
|