A lightweight self-hosted alternative to DocSearch.
site-search
will run your website locally, crawl its pages and index their content in a lunr
index. It also provides a node.js request handler that can be initialized with this index to provide a search endpoint for your website.
- Install the package
yarn add -D site-search
- Add a
site-search.config.js
to the root of your project containing
module.exports = {
siteStartCmd: `yarn start`,
siteOrigin: 'http://localhost:3000',
startUrl: '/',
outputPath: './site-search-index.json',
rules: [
{
hierarchy: [
{ selector: 'h1' },
{ selector: 'h2' },
{ selector: 'h3' },
{ selector: 'h4' },
],
text: { selector: 'p' },
},
],
};
-
Run
site-search
: -
Add the search endpoint to your app:
const path = require('path');
const handler = require('site-search/handler');
// ...
app.use(
'/search',
handler({
filename: path.resolve(__dirname, '../site-search-index.json'),
})
);
- Now you can use
/search?q=foo
to find documents matching "foo"
siteStartCmd
: Command that should be run to start your website
siteOrigin
: Url of where the running website can be reached
startUrl
: Url where crawling should start
outputPath
: Where to store the resulting index data
rules
: Rules to extract hierarchy. A bit similar to how Algolia does it