Indexing Docs
class IndexDocsToAlgolia extends Command { protected $signature = 'index:docs'; protected $description = 'Index docs to Algolia';
public function handle()
{
$client = SearchClient::create('YourApplicationID', 'YourAdminAPIKey');
$index = $client->initIndex('my-docs');
$docs = $this->loadDocs(); // Implement this method to load your docs
foreach ($docs as $doc) {
$index->saveObject([
'objectID' => $doc['id'],
'title' => $doc['title'],
'content' => $doc['content'],
]);
}
$this->info('Docs have been indexed to Algolia');
}
}</code></pre>
</li> <li>Run the command to index your docs: <pre><code>php artisan index:docs</code></pre> </li> </ul> <p><strong>Update Frontend</strong></p> <ul> <li>Modify the <code>docsearch</code> script in your HTML:</li> <pre><code>docsearch({ apiKey: 'YourSearchOnlyAPIKey', indexName: 'my-docs', inputSelector: '.search', debug: false }); </code></pre> </ul>Hi,
The Wave docs uses the Algoia DocSearch, so no need to install the Laravel packages, just update your JS code with your API key and App ID:
<script type="text/javascript"> docsearch({
apiKey: 'your_search_api_key',
indexName: 'your_index_name',
appId: 'your_app_id',
inputSelector: '.search',
debug: true // Set debug to true if you want to inspect the dropdown
});
</script>
Then the Algolia DocSearch requires you to submit your site to them for indexing before it starts working.
For more information, refer to Algolia DocSearch's documentation:
But you can feel free to change the logic in the search and use something like larecipe instead:
- Bobby
Oh just saw that you updated the question! That could also work, it would be a matter of personal preference on which approach you decide to pick.
