Skip to content

Commit

Permalink
Pull from schema fields if we have them
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Aug 20, 2024
1 parent 614deb1 commit 88b5b84
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Typesense/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 88b5b84

Please sign in to comment.