advanced-search-library
v1.1.0
Published
Intelligent search library with typo correction, autocomplete, and flexible data structure support
Maintainers
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 relevanceprice_asc/price_desc- By pricename_asc/name_desc- By namerating_desc- By ratingnewest- 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 fieldsPerformance Optimization
// Test with 1000+ items
const results = search.search("product");
// Average search time: ~10ms for 1000 itemsMulti-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-basicAdvanced Features
npm run example-advancedFlexible Data Structures
npm run example-flexibleWeb Demo
npm run demo
# Then open demo/index.html in your browser🧪 Testing
npm testTest 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
- GitHub: @Ridvan0
- LinkedIn: ridvansevindik
- Email: [email protected]
🔗 Links
- GitHub Profile: https://github.com/Ridvan0
- GitHub Repository: https://github.com/Ridvan0/turkish-search
- Issues: Report a bug
- LinkedIn: Rıdvan Sevindik
🌟 Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
