Question By
Solved
Solved
scraghty

Sep 3rd, 2024 03:19 AM

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

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>
bobbyiliev

Sep 3rd, 2024 04:02 AM

Best Answer

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:

https://docsearch.algolia.com/docs/what-is-docsearch

But you can feel free to change the logic in the search and use something like larecipe instead:

https://devdojo.com/episode/larecipe

- Bobby

bobbyiliev

Sep 3rd, 2024 04:02 AM

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.