Implement Search Functionality
Adding search functionality to your MyLittleContentEngine site makes it easier for users to find relevant content quickly. This guide shows you how to integrate Algolia DocSearch for powerful, client-side search capabilities.
Prerequisites
Before implementing search, ensure you have:
- A deployed MyLittleContentEngine site
- Content that's publicly accessible - Algolia doesn't work locally
- Administrative access to configure search settings
- 1
Set up Algolia DocSearch
Create an Algolia Account
- Visit docsearch.algolia.com
- Click "Apply for DocSearch" if you qualify for the free tier (open source projects, technical documentation)
- Alternatively, create a paid Algolia account at algolia.com
Configure Your Search Index
For free DocSearch:
- Fill out the application form with your site details
- Wait for approval (typically 1-2 weeks)
- Once approved, you'll receive your search credentials
- 2
Add Search Scripts
MyLittleContentEngine.UI includes built-in support for DocSearch. The required JavaScript is already included in the
scripts.js
file that's part of theMyLittleContentEngine.UI package
.dotnet add package MyLittleContentEngine.UI
Then make sure to include the UI scripts in your project:
<script src="_content/MyLittleContentEngine.UI/scripts.js" defer></script>
- 3
Add Search Component to Your Layout
Add the search container to your site's header or navigation area:
<div id="docsearch" data-search-app-id="YOUR_APP_ID" data-search-index-name="YOUR_INDEX_NAME" data-search-api-key="YOUR_SEARCH_API_KEY"> </div>
- 4
Customize Search Appearance (Optional)
MyLittleContentEngine.MonorailCss
will automatically style the search component using yourbase
,primary
andaccent
colors.