Skip to content

Commit

Permalink
Typesense Collection Settings: Query Params
Browse files Browse the repository at this point in the history
  • Loading branch information
karakhanyans committed Nov 10, 2023
1 parent 18d08f6 commit e875e90
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
46 changes: 26 additions & 20 deletions config/scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
*/

'typesense' => [
'client_configuration' => [
'client-settings' => [
'api_key' => env('TYPESENSE_API_KEY', 'xyz'),
'nodes' => [
[
Expand All @@ -174,25 +174,31 @@
'num_retries' => env('TYPESENSE_NUM_RETRIES', 3),
'retry_interval_seconds' => env('TYPESENSE_RETRY_INTERVAL_SECONDS', 1),
],
'model_configuration' => [
// 'users' => [ // name of the table
// 'name' => 'users', // name of the table
// 'fields' => [
// [
// 'name' => 'id',
// 'type' => 'string',
// ],
// [
// 'name' => 'name',
// 'type' => 'string',
// ],
// [
// 'name' => 'created_at',
// 'type' => 'int64',
// ],
// ],
// 'default_sorting_field' => 'created_at',
// ],
'collection-settings' => [
// User::class => [
// 'schema' => [
// 'fields' => [
// [
// 'name' => 'id',
// 'type' => 'string',
// ],
// [
// 'name' => 'name',
// 'type' => 'string',
// ],
// [
// 'name' => 'created_at',
// 'type' => 'int64',
// ],
// ],
// 'default_sorting_field' => 'created_at',
// ],
// 'search-options' => [
// 'query_by' => [
// 'name',
// ],
// ],
// ],
],
],
];
2 changes: 1 addition & 1 deletion src/EngineManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function createTypesenseDriver()
{
$this->ensureTypesenseClientIsInstalled();

return new TypesenseEngine(new Typesense(config('scout.typesense.client_configuration')));
return new TypesenseEngine(new Typesense(config('scout.typesense.client-settings')));
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Engines/TypesenseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function buildSearchParameters(Builder $builder, int $page, int|null $per
{
$params = [
'q' => $builder->query,
'query_by' => '',
'query_by' => implode(',', config('scout.typesense.collection-settings.'.get_class($builder->model).'.search-options.query_by')) ?? '',
'filter_by' => $this->filters($builder),
'per_page' => $perPage,
'page' => $page,
Expand Down Expand Up @@ -509,7 +509,11 @@ protected function getOrCreateCollectionFromModel($model): TypesenseCollection

return $index;
} catch (ObjectNotFound $exception) {
$schema = config('scout.typesense.model_configuration.'.$model->getTable()) ?? [];
$schema = config('scout.typesense.collection-settings.'.get_class($model).'.schema') ?? [];

if (!isset($schema['name'])) {
$schema['name'] = $model->searchableAs();
}

$this->typesense->getCollections()->create($schema);

Expand Down

0 comments on commit e875e90

Please sign in to comment.