Indexing Docs
Issue:
I've set up my own .md
files in the docs. However, when I use the search, it returns old content from the original Wave setup.
Question:
How do I re-index the docs so Algolia can see the new content? Do I need to create my own index using Algolia?
Current Setup:
<!-- wave/docs/index.blade.php -->
<script type="text/javascript">
docsearch({
apiKey: '57b9a8aca979f9716f86aa3d2b75a415',
indexName: 'devdojo',
inputSelector: '.search',
debug: false
});
</script>
Proposed Steps (Is this Correct?):
Create an Index
- In Algolia dashboard, click "Indices" > "Create Index."
- Name the index (e.g.,
my-docs
).
Install Algolia in Laravel
- Run:
composer require algolia/algoliasearch-client-php
Create an Artisan Command to Index Your .md
Files
- Generate the Artisan command:
php artisan make:command IndexDocsToAlgolia
- Add the following logic in
app/Console/Commands/IndexDocsToAlgolia.php
:use Algolia\AlgoliaSearch\SearchClient; use Illuminate\Console\Command; <p>class IndexDocsToAlgolia extends Command { protected $signature = 'index:docs'; protected $description = 'Index docs to Algolia';</p> <pre><code>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'); }
}
- Run the command to index your docs:
php artisan index:docs
Update Frontend
- Modify the
docsearch
script in your HTML:
docsearch({
apiKey: 'YourSearchOnlyAPIKey',
indexName: 'my-docs',
inputSelector: '.search',
debug: false
});
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.