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 🙏

© 2026 – Pkg Stats / Ryan Hefner

advanced-search-library

v1.1.0

Published

Intelligent search library with typo correction, autocomplete, and flexible data structure support

Readme

🔍 Advanced Search Library - Intelligent Search with Typo Correction

An advanced search library featuring typo correction, autocomplete, and flexible data structure support with optimized results ranking.

✨ Features

  • 🚀 High Performance: Millisecond search response times
  • 🔧 Typo Correction: "cofee" → "coffee", "phoen" → "phone"
  • 📝 Autocomplete: Smart suggestions after 3+ characters
  • 📊 Field-based Priority: Intelligent scoring based on name, title, description, etc.
  • 🔄 Flexible Data Structure: Compatible with any JSON data format
  • 🎯 Auto Field Detection: Automatically analyzes and prioritizes data structure
  • 🔍 Advanced Filtering: Price, brand, category-based filtering
  • 💾 Search History: Search history management and analytics
  • 📱 Modern UI: Responsive and user-friendly interface
  • 🌐 Universal: Works in Node.js and browsers

🚀 Quick Start

const AdvancedSearch = require('./src/AdvancedSearch');

// Create search engine (compatible with any data structure)
const search = new AdvancedSearch({
  // You can specify custom fields
  customFields: [
    { field: 'name', priority: 10, exact: 20 },
    { field: 'description', priority: 5, exact: 10 },
    { field: 'tags', priority: 7, exact: 14 }
  ]
});

// Add data - any structure works
search.addData([
  { id: 1, name: "Coffee Machine", category: "Appliances", price: 299, tags: ["coffee", "automatic"] },
  { id: 2, title: "Tea Cup Set", description: "Glass cup set", price: 89 },
  { id: 3, name: "Drum Set", category: "Music", price: 1299, keywords: ["instrument"] }
]);

// Search with field-based priority scoring
const results = search.search("cofee"); // Corrected to "coffee"
console.log(results);

📖 API Documentation

Constructor Options

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | maxResults | number | 50 | Maximum number of results | | minQueryLength | number | 1 | Minimum query length for search | | typoThreshold | number | 2 | Maximum edit distance for typo correction | | historyLimit | number | 100 | Maximum search history entries | | customFields | array | auto-detected | Custom field configuration | | autoDetectFields | boolean | true | Automatically detect fields from data |

Custom Field Configuration

const search = new AdvancedSearch({
  customFields: [
    { field: 'name', priority: 15, exact: 25 },      // High priority for exact matches
    { field: 'title', priority: 15, exact: 25 },
    { field: 'description', priority: 8, exact: 12 },
    { field: 'tags', priority: 10, exact: 18 },
    { field: 'category', priority: 12, exact: 20 }
  ]
});

Main Methods

addData(items)

Adds data to the search index. Accepts single item or array.

search.addData([
  { id: 1, name: "Product 1", category: "Electronics" },
  { id: 2, title: "Product 2", type: "Books" }
]);

search(query, filters = {})

Performs search with optional filters.

const results = search.search("laptop", {
  category: "Electronics",
  priceRange: [500, 2000],
  minRating: 4.0,
  sortBy: "price_asc"
});

autocomplete(query)

Returns autocomplete suggestions.

const suggestions = search.autocomplete("lap"); // ["laptop", "lamp", ...]

Filter Options

const filters = {
  category: "Electronics",           // Category filter
  priceRange: [100, 500],           // Price range [min, max]
  brand: "Apple",                   // Brand filter
  minRating: 4.0,                   // Minimum rating
  sortBy: "price_asc"               // Sort options
};

Sort Options

  • relevance (default) - By search relevance
  • price_asc / price_desc - By price
  • name_asc / name_desc - By name
  • rating_desc - By rating
  • newest - By creation date

🎯 Advanced Usage

Auto Field Detection

The library automatically detects and prioritizes fields in your data:

const search = new AdvancedSearch();

// Different data structures work automatically
search.addData([
  { productName: "Phone", specs: "Smart device", manufacturer: "Apple" },
  { title: "Book", content: "Programming guide", author: "John Doe" },
  { name: "Shirt", details: "Cotton fabric", brand: "Nike" }
]);

// Library automatically detects: productName, title, name as high-priority fields

Performance Optimization

// Test with 1000+ items
const results = search.search("product"); 
// Average search time: ~10ms for 1000 items

Multi-language Support

const search = new AdvancedSearch({
  typoMap: {
    // Add your language-specific typo corrections
    'computer': 'computer',
    'compter': 'computer',
    'komputr': 'computer'
  }
});

📊 Examples

Basic Usage

npm run example-basic

Advanced Features

npm run example-advanced

Flexible Data Structures

npm run example-flexible

Web Demo

npm run demo
# Then open demo/index.html in your browser

🧪 Testing

npm test

Test Results: 16/16 tests passing ✅

📈 Performance Benchmarks

| Dataset Size | Search Time | Memory Usage | |--------------|-------------|--------------| | 100 items | 0.5ms | ~2MB | | 1,000 items | 5ms | ~15MB | | 10,000 items | 45ms | ~120MB |

🔧 Configuration Examples

E-commerce Setup

const ecommerceSearch = new AdvancedSearch({
  customFields: [
    { field: 'name', priority: 20, exact: 40 },
    { field: 'brand', priority: 15, exact: 30 },
    { field: 'category', priority: 12, exact: 24 },
    { field: 'description', priority: 8, exact: 16 },
    { field: 'tags', priority: 10, exact: 20 }
  ]
});

Blog/Content Setup

const blogSearch = new AdvancedSearch({
  customFields: [
    { field: 'title', priority: 25, exact: 50 },
    { field: 'summary', priority: 15, exact: 30 },
    { field: 'content', priority: 5, exact: 10 },
    { field: 'tags', priority: 12, exact: 24 },
    { field: 'author', priority: 8, exact: 16 }
  ]
});

🛠️ Browser Usage

<script src="src/AdvancedSearch.js"></script>
<script>
  const search = new AdvancedSearch();
  search.addData(yourData);
  const results = search.search("query");
</script>

📄 License

MIT License - see LICENSE file for details.

👨‍💻 Developer

Rıdvan Sevindik

🔗 Links

🌟 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 Changelog

v1.1.0

  • ✅ Flexible data structure support
  • ✅ Auto field detection
  • ✅ Enhanced relevance scoring
  • ✅ Multi-word search improvements
  • ✅ Performance optimizations

v1.0.0

  • ✅ Initial release
  • ✅ Basic search functionality
  • ✅ Typo correction
  • ✅ Autocomplete
  • ✅ Filtering and sorting