From 88b5b844f79bc714fd867f1f5c2da13d476075a7 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Tue, 20 Aug 2024 07:44:00 +0100 Subject: [PATCH] Pull from schema fields if we have them --- src/Typesense/Index.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Typesense/Index.php b/src/Typesense/Index.php index d09682d..c2158a8 100644 --- a/src/Typesense/Index.php +++ b/src/Typesense/Index.php @@ -92,9 +92,15 @@ public function searchUsingApi($query, array $options = []): Collection { $options['q'] = $query; - // if we have no query_by then we query on all string fields if (! isset($options['query_by'])) { - $options['query_by'] = '*'; + $schema = Arr::get($this->config, 'settings.schema', []); + + // if we have fields in our schema use any strings, otherwise * + $options['query_by'] = collect($schema['fields'] ?? []) + ->filter(fn ($field) => $field['type'] == 'string') + ->map(fn ($field) => $field['name']) + ->values() + ->join(',') ?: '*'; } $searchResults = $this->getOrCreateIndex()->documents->search($options);