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:
npm install staticseek
pnpm install staticseek
yarn add 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 indexconst index = createIndex(LinearIndex, array_of_articles);if (index instanceof StaticSeekError) throw index;
// Perform a searchconst result = await search(index, "search word");if (result instanceof StaticSeekError) throw result;for (const r of result) { console.log(array_of_articles[r.id]);}
export const array_of_articles = [ { slug: "introduction-to-js", content: "JavaScript is a versatile programming language widely used for web development...", data: { title: "Introduction to JavaScript", description: "Learn the basics of JavaScript, a powerful language for modern web applications.", tags: ["javascript", "web", "programming"] } }, // ...];
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.