Download and extract Typesense server:
# Download Typesense (check https://typesense.org/downloads/ for latest version)
wget https://dl.typesense.org/releases/0.25.1/typesense-server-0.25.1-linux-amd64.tar.gz
# Extract the archive
tar -xvf typesense-server-0.25.1-linux-amd64.tar.gz
# Make it executable (if needed)
chmod +x typesense-server# Create data directory for Typesense
mkdir -p typesense-data# Typesense Server Configuration
TYPESENSE_DATA_DIR=typesense-data
TYPESENSE_API_KEY=
TYPESENSE_HOST=localhost
TYPESENSE_PORT=8108
TYPESENSE_PROTOCOL=http
# Frontend Configuration (for your Docusaurus site) add these in docs repo
NEXT_PUBLIC_TYPESENSE_PROTOCOL=http
NEXT_PUBLIC_TYPESENSE_HOST=localhost
NEXT_PUBLIC_TYPESENSE_PORT=8108
NEXT_PUBLIC_TYPESENSE_API_KEY=
NEXT_PUBLIC_TYPESENSE_COLLECTION_NAME=solidxaiDocsNote: The
TYPESENSE_API_KEYis your admin key (keep it secret!). TheNEXT_PUBLIC_TYPESENSE_API_KEYis your search-only key (safe for frontend).
Create a file named start-typesense.sh:
#!/bin/bash
# Load environment variables from .env file
export $(grep -v '^#' .env | xargs)
# Start Typesense server
./typesense-server \
--data-dir "$TYPESENSE_DATA_DIR" \
--api-key "$TYPESENSE_API_KEY" \
--listen-address "$TYPESENSE_HOST" \
--listen-port "$TYPESENSE_PORT" \
--enable-corsMake it executable:
chmod +x start-typesense.shFirst, start Typesense server:
./start-typesense.shIn a new terminal, create a search-only API key:
curl -X POST "http://localhost:8108/keys" \
-H "X-TYPESENSE-API-KEY: " \
-H "Content-Type: application/json" \
-d '{
"description": "Search-only key for frontend",
"actions": ["documents:search"],
"collections": ["*"]
}'This will return a response with your search-only key. Copy the value field and update NEXT_PUBLIC_TYPESENSE_API_KEY in your .env file.
Example response:
{
"id": 1,
"value": "9kRQHXPASD1El98dGAcTtYdNfPPMmIFW",
"description": "Search-only key for frontend",
"actions": ["documents:search"],
"collections": ["*"]
}git clone https://github.com/typesense/typesense-docsearch-scraper.git
cd typesense-docsearch-scraper# Install pipenv if not already installed
pip install pipenv
# Install dependencies
pipenv install
# Activate the virtual environment
pipenv shell{
"index_name": "solidxaiDocs",
"allowed_domains": [
"localhost"
],
"start_urls": [
{
"url": "http://localhost:3000/"
}
],
"sitemap_urls": [
"http://localhost:3000/sitemap.xml"
],
"stop_urls": [
"/search",
"/tags",
"\\?",
"\\.pdf$"
],
"excludeSelectors": [
".breadcrumbs",
".breadcrumbs__item",
"nav.breadcrumbs",
"nav.menu",
".menu",
".menu__list",
".menu__list-item",
".menu__link",
".theme-doc-sidebar-item-category",
".theme-doc-sidebar-item-link"
],
"selectors": {
"default": {
"lvl0": {
"selector": "nav.menu a.menu__link--active",
"default_value": "Documentation"
},
"lvl1": "article h1",
"lvl2": "article h2",
"lvl3": "article h3",
"lvl4": "article h4",
"lvl5": "article h5",
"lvl6": "article h6",
"text": "article p, article li, article td, article th, article blockquote",
"code": "article pre code"
}
},
"custom_settings": {
"separatorsToIndex": "_",
"attributesToRetrieve": [
"hierarchy",
"content",
"anchor",
"url",
"tags",
"type"
],
"attributesToHighlight": [
"hierarchy",
"content"
],
"attributesToSnippet": [
"content:40"
],
"searchableAttributes": [
"unordered(hierarchy.lvl0)",
"unordered(hierarchy.lvl1)",
"unordered(hierarchy.lvl2)",
"unordered(hierarchy.lvl3)",
"unordered(hierarchy.lvl4)",
"unordered(hierarchy.lvl5)",
"unordered(hierarchy.lvl6)",
"content"
]
},
"min_indexed_level": 0,
"nb_hits": 14323
}Important: Make sure
index_namematchesNEXT_PUBLIC_TYPESENSE_COLLECTION_NAMEin your.envfile.
# Go back to your Docusaurus project directory
cd /path/to/your/docusaurus/project
# Install dependencies
npm installOpen Terminal 1:
./start-typesense.shKeep this terminal running.
Open Terminal 2:
npm run build
npm run serveThis will start your documentation site at http://localhost:3000. Keep this terminal running.
Open Terminal 3:
# Go to scraper directory
cd /path/to/typesense-docsearch-scraper
# Activate pipenv shell (if not already active)
pipenv shell
# Run the scraper
./docsearch run config.jsonWait for the scraper to finish indexing. You should see output indicating how many documents were indexed.
Go to http://localhost:3000 and test the search functionality. Your documentation should now be searchable!
ps aux | grep typesensepkill -f typesense-servercurl http://localhost:8108/healthcurl -H "X-TYPESENSE-API-KEY: " \
http://localhost:8108/collections