By default, only the page title, URL, description, and some content are added to the search index. However, you can add any extra property you want.
You do this by using a custom indexer and override the extra
method.
class YourIndexer extends Spatie\SiteSearch\Indexers\DefaultIndexer
{
public function extra() : array{
return [
'authorName' => $this->functionThatExtractsAuthorName()
]
}
public function functionThatExtractsAuthorName()
{
}
}
The extra properties will be available on a search result hit.
$searchResults = SearchIndexQuery::onIndex('my-index')->search('your query')->get();
$firstHit = $searchResults->hits->first();
$firstHit->authorName;
All extra properties are searchable by default. If you don't want any of your extra attributes to be searchable, you must customize the search index settings.