npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@obinexuscomputing/nexus-search

v0.1.55-rc

Published

A high-performance search indexing and query system that uses a trie data structure and BFS/DFS algorithms for fast full-text search with fuzzy matching.

Downloads

1,106

Readme

OBINexusComputing - Computing from the Heart

NexusSearch

A high-performance search indexing and query system that uses a trie data structure and BFS/DFS algorithms for fast full-text search with fuzzy matching, real-time updates, and flexible configuration.

Repo:

[https://github.com/obinexuscomputing/nexus-search](Nexus Search on Github)

Features

  • Fast full-text search with fuzzy matching using a trie data structure
  • Real-time indexing and updates
  • Customizable search options and scoring
  • TypeScript support
  • Works in both browser and Node.js environments
  • Persistent storage with IndexedDB
  • Support for nested document fields
  • Built-in caching system

Search Philosophy

NexusSearch uses a trie data structure to store the indexed documents. Each node in the trie represents characters, and the path from the root to a leaf node represents a word from the indexed documents. This structure allows for efficient prefix-based searches and fuzzy matching.

The search process involves traversing the trie using either a breadth-first search (BFS) or depth-first search (DFS) algorithm. BFS is generally better for finding the most relevant results, as it explores all nodes at the current depth before moving on to the next depth level. DFS, on the other hand, is better for finding the first matching results quickly.

The choice between BFS and DFS can be made based on the specific use case and requirements of the search engine. For example, if speed is the primary concern, DFS might be the better choice. If relevance is more important, BFS could be the preferred algorithm.

Use it with a html search bar,node or your favourite library.

Installation

npm install @obinexuscomputing/nexus-search
# or
yarn add @obinexuscomputing/nexus-search

Quick Start

import { SearchEngine } from '@obinexuscomputing/nexus-search';

// Initialize search engine
const searchEngine = new SearchEngine({
  name: 'my-search-index',
  version: 1,
  fields: ['title', 'content', 'tags']
});

// Initialize and add documents
await searchEngine.initialize();
await searchEngine.addDocuments([
  {
    title: 'Getting Started',
    content: 'Quick start guide for NexusSearch',
    tags: ['documentation', 'guide']
  }
]);

// Perform search with options
const results = await searchEngine.search('quick start', {
  fuzzy: true,
  maxResults: 5,
  algorithm: 'bfs' // or 'dfs'
});

Core Concepts

Search Engine Configuration

const config: IndexConfig = {
  name: 'custom-index',      // Unique identifier for the index
  version: 1,                // Version for migration support
  fields: ['title', 'tags'], // Fields to index
  options: {
    caseSensitive: false,
    stemming: true,
    stopWords: ['the', 'and', 'or'],
    fuzzyThreshold: 0.8
  }
};

Search Options

const searchOptions: SearchOptions = {
  fuzzy: true,              // Enable fuzzy matching
  maxResults: 20,           // Limit results
  threshold: 0.6,           // Minimum relevance score
  fields: ['title', 'tags'], // Fields to search in
  algorithm: 'bfs'          // or 'dfs'
};

Use Cases

Document Search

const searchEngine = new SearchEngine({
  name: 'documents',
  version: 1,
  fields: ['title', 'content', 'author', 'tags']
});

await searchEngine.addDocuments([
  {
    title: 'TypeScript Guide',
    content: 'Introduction to TypeScript...',
    author: 'John Doe',
    tags: ['typescript', 'programming']
  }
]);

const results = await searchEngine.search('typescript');

Real-time Search

class RealTimeSearch {
  private searchEngine: SearchEngine;
  private updateQueue: any[] = [];

  constructor() {
    this.searchEngine = new SearchEngine({
      name: 'realtime-search',
      version: 1,
      fields: ['title', 'content']
    });
  }

  async addDocument(document: any) {
    await this.searchEngine.addDocuments([document]);
  }

  async search(query: string) {
    return this.searchEngine.search(query, {
      maxResults: 10,
      fuzzy: true,
      algorithm: 'bfs'
    });
  }
}

API Reference

SearchEngine

The main class for managing search operations.

Methods

  • initialize(): Initialize the search engine
  • addDocuments<T>(documents: T[]): Add documents to the index
  • search<T>(query: string, options?: SearchOptions): Perform a search
  • clearIndex(): Clear all indexed data

SearchResult

interface SearchResult<T> {
  item: T;                    // The matched document
  score: number;              // Relevance score
  matches: string[];          // Matched terms
  highlights?: Record<string, string[]>; // Highlighted matches
}

Best Practices

  1. Index Configuration

    • Choose appropriate fields for indexing
    • Configure options based on data characteristics
    • Use meaningful index names
  2. Performance

    • Index only necessary fields
    • Implement pagination for large result sets
    • Use appropriate fuzzy thresholds
    • Choose the appropriate search algorithm (BFS or DFS) based on requirements
  3. Search Implementation

    • Use fuzzy search for better matches
    • Implement proper error handling
    • Cache frequent searches

Example Projects

Development

# Install dependencies
npm install

# Build the library
npm run build

# Run tests
npm test

# Run demos
npm run demo

Contributing

Coming soon...

Support and Community