Skip to content

Getting Started

staticseek is a client-side full-text search engine designed specifically for static websites. It enables searching through arrays of JavaScript objects containing strings or string arrays. By converting your articles into JavaScript objects, you can implement full-text search functionality on static sites without any server-side implementation.

Quick Start

Install staticseek

Install staticseek to your project by running the following command in your terminal:

Terminal window
npm install staticseek

Perform Indexing and Searching

Create an index and run searches with that index by providing search terms as arguments. Here, array_of_articles represents an array of JavaScript objects containing the text to be searched.

import { LinearIndex, createIndex, search, StaticSeekError } from "staticseek";
import { array_of_articles } from "array_of_articles";
// Create an index
const index = createIndex(LinearIndex, array_of_articles);
if (index instanceof StaticSeekError) throw index;
// Perform a search
const result = await search(index, "search word");
if (result instanceof StaticSeekError) throw result;
for (const r of result) {
console.log(array_of_articles[r.id]);
}

The search results are returned as an array, sorted by score (relevance). The id field in each result contains the array index of the matching document.