All Projects → bvaughn → Js Worker Search

bvaughn / Js Worker Search

Licence: mit
JavaScript client-side search API with web-worker support

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Js Worker Search

Js Search
JS Search is an efficient, client-side search library for JavaScript and JSON objects
Stars: ✭ 1,920 (+456.52%)
Mutual labels:  search, indexing, database, performance
Filemasta
A search application to explore, discover and share online files
Stars: ✭ 571 (+65.51%)
Mutual labels:  search, indexing, database
Manticoresearch
Database for search
Stars: ✭ 610 (+76.81%)
Mutual labels:  search, database
Euclidesdb
A multi-model machine learning feature embedding database
Stars: ✭ 615 (+78.26%)
Mutual labels:  search, database
Sonic
🦔 Fast, lightweight & schema-less search backend. An alternative to Elasticsearch that runs on a few MBs of RAM.
Stars: ✭ 12,347 (+3478.84%)
Mutual labels:  search, database
Awesome Elasticsearch
A curated list of the most important and useful resources about elasticsearch: articles, videos, blogs, tips and tricks, use cases. All about Elasticsearch!
Stars: ✭ 4,168 (+1108.12%)
Mutual labels:  search, database
Opensearchserver
Open-source Enterprise Grade Search Engine Software
Stars: ✭ 408 (+18.26%)
Mutual labels:  search, indexing
Search And Replace
A simple search for find strings in your WordPress database and replace the string.
Stars: ✭ 76 (-77.97%)
Mutual labels:  search, database
Deepdatabase
A relational database engine using B+ tree indexing
Stars: ✭ 32 (-90.72%)
Mutual labels:  indexing, database
rgpipe
lesspipe for ripgrep for common new filetypes using few dependencies
Stars: ✭ 21 (-93.91%)
Mutual labels:  search, indexing
Rusticsearch
Lightweight Elasticsearch compatible search server.
Stars: ✭ 171 (-50.43%)
Mutual labels:  search, database
Query track
Find time-consuming database queries for ActiveRecord-based Rails Apps
Stars: ✭ 258 (-25.22%)
Mutual labels:  database, performance
Dbreeze
C# .NET MONO NOSQL ( key value store embedded ) ACID multi-paradigm database management system.
Stars: ✭ 383 (+11.01%)
Mutual labels:  search, database
Xapiand
Xapiand: A RESTful Search Engine
Stars: ✭ 347 (+0.58%)
Mutual labels:  search, indexing
Pumpkindb
Immutable Ordered Key-Value Database Engine
Stars: ✭ 1,219 (+253.33%)
Mutual labels:  indexing, database
Spimedb
EXPLORE & EDIT REALITY
Stars: ✭ 14 (-95.94%)
Mutual labels:  search, database
Pgm Index
🏅State-of-the-art learned data structure that enables fast lookup, predecessor, range searches and updates in arrays of billions of items using orders of magnitude less space than traditional indexes
Stars: ✭ 499 (+44.64%)
Mutual labels:  indexing, database
Hypopg
Hypothetical Indexes for PostgreSQL
Stars: ✭ 594 (+72.17%)
Mutual labels:  indexing, database
Toshi
A full-text search engine in rust
Stars: ✭ 3,373 (+877.68%)
Mutual labels:  search, indexing
Database validations
Database validations for ActiveRecord
Stars: ✭ 274 (-20.58%)
Mutual labels:  database, performance

js-worker-search

NPM version NPM license NPM total downloads NPM monthly downloads

Full text client-side search based on js-search but with added web-worker support for better performance.

Check out the redux-search for an example integration.

Or install it yourself with NPM:

npm install --save js-worker-search

SearchApi Documentation

Forked from JS search, this utility builds a search index and runs actual searches. It auto-detects the capabilities of the current environment (browser or Node) and uses a web-worker based implementation when possible. When no web-worker support is available searching is done on the main (UI) thread.

SearchApi defines the following public methods:

constructor ({ caseSensitive, indexMode, tokenizePattern })

By default, SearchApi builds an index to match all substrings. You can override this behavior by passing an named indexMode parameter. Valid values are INDEX_MODES.ALL_SUBSTRINGS, INDEX_MODES.EXACT_WORDS, and INDEX_MODES.PREFIXES.

Searches are case insensitive by default and split on all whitespace characters. Read below for more information on customizing default options.

indexDocument (uid, text)

Adds or updates a uid in the search index and associates it with the specified text. Note that at this time uids can only be added or updated in the index, not removed.

Parameters:

  • uid: Uniquely identifies a searchable object
  • text: Searchable text to associate with the uid
search(query)

Searches the current index for the specified query text. Only uids matching all of the words within the text will be accepted. If an empty query string is provided all indexed uids will be returned.

Document searches are case-insensitive (e.g. "search" will match "Search"). Document searches use substring matching (e.g. "na" and "me" will both match "name").

Parameters:

  • query: Searchable query text

This method will return an array of uids.

terminate()

If search is running in a web worker, this will terminate the worker to allow for garbage collection.

Example Usage

Use the API like so:

import SearchApi from 'js-worker-search'

const searchApi = new SearchApi()

// Index as many objects as you want.
// Objects are identified by an id (the first parameter).
// Each Object can be indexed multiple times (once per string of related text).
searchApi.indexDocument('foo', 'Text describing an Object identified as "foo"')
searchApi.indexDocument('bar', 'Text describing an Object identified as "bar"')

// Search for matching documents using the `search` method.
// In this case the promise will be resolved with the Array ['foo', 'bar'].
// This is because the word "describing" appears in both indices.
const promise = searchApi.search('describing')

Custom index mode

By default, SearchApi builds an index to match all substrings. You can override this behavior by passing an indexMode parameter to the constructor like so:

import SearchApi, { INDEX_MODES } from 'js-worker-search'

// all-substrings match by default; same as current
// eg "c", "ca", "a", "at", "cat" match "cat"
const searchApi = new SearchApi()

// prefix matching (eg "c", "ca", "cat" match "cat")
const searchApi = new SearchApi({
  indexMode: INDEX_MODES.PREFIXES
})

// exact words matching (eg only "cat" matches "cat")
const searchApi = new SearchApi({
  indexMode: INDEX_MODES.EXACT_WORDS
})

Custom tokenizer patterns

By default, SearchApi breaks text into words (tokenizes) using spaces and newlines as the delimiting character. If you want to provide your own splitting rule, pass a RegExp to the constructor that defines the pattern , like so:

// Custom tokenizer pattern to include all non alphanumerics as delimeters
// ex: searching "Swift" matches "Thomas Swift" and "Thomas (Swift)" but not "swiftly tilting"
const searchApi = new SearchApi({
    indexMode: INDEX_MODES.EXACT_WORDS,
    tokenizePattern: /[^a-z0-9]+/,
})

Case-sensitive searches

The default sanitizer performs a case-insensitive search. If you want to override that behavior and do a case-sensitive search, set the caseSensitive bit to true, like so:

// custom sanitizer for case-sensitive searches
const searchApi = new SearchApi({
  caseSensitive: true
})

Partial matches

By default, the search utility only returns documents containing every search token. It can be configured to return documents containing any search token.

// Change search behavior from AND to OR
const searchApi = new SearchApi({
  matchAnyToken: true
})

Changelog

Changes are tracked in the changelog.

License

js-worker-search is available under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].