Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
flexsearch
Advanced tools
FlexSearch is a high-performance, full-text search library for JavaScript. It is designed to be fast and efficient, providing a variety of indexing and search capabilities. FlexSearch can be used in both Node.js and browser environments, making it versatile for different types of applications.
Indexing
FlexSearch allows you to create an index and add documents to it. Each document is associated with a unique ID.
const FlexSearch = require('flexsearch');
const index = new FlexSearch();
index.add(1, 'Hello World');
index.add(2, 'Hi there');
Searching
You can perform searches on the indexed documents. The search results will return the IDs of the matching documents.
index.search('Hello', function(results) {
console.log(results); // [1]
});
Asynchronous Search
FlexSearch supports asynchronous search operations, which can be useful for handling large datasets or integrating with other asynchronous workflows.
index.search('Hello').then(function(results) {
console.log(results); // [1]
});
Custom Configuration
FlexSearch allows for extensive customization of the indexing and search process. You can configure encoding, tokenization, threshold, and resolution to suit your specific needs.
const customIndex = new FlexSearch({
encode: 'icase',
tokenize: 'forward',
threshold: 0,
resolution: 3
});
customIndex.add(1, 'Custom configuration example');
Lunr.js is a small, full-text search library for use in the browser and Node.js. It provides a simple and easy-to-use API for indexing and searching documents. Compared to FlexSearch, Lunr.js is more lightweight but may not offer the same level of performance and customization.
Elasticlunr.js is a lightweight full-text search library that is inspired by Lunr.js and Elasticsearch. It offers more features than Lunr.js, such as support for multiple languages and more advanced search capabilities. However, it may still not match the performance and flexibility of FlexSearch.
Search-Index is a powerful, full-text search library for Node.js and the browser. It provides a wide range of features, including real-time indexing, faceted search, and more. While it offers more advanced features than FlexSearch, it may be more complex to set up and use.
When it comes to raw search speed FlexSearch outperforms every single searching library out there and also provides flexible search capabilities like multi-word matching, phonetic transformations or partial matching. It also has the most memory-efficient index. Keep in mind that updating existing items from the index has a significant cost. When your index needs to be updated continuously then BulkSearch may be a better choice. FlexSearch also provides you a non-blocking asynchronous processing model as well as web workers to perform any updates on the index as well as queries through dedicated threads.
Benchmark:
Supported Platforms:
Supported Module Definitions:
All Features:
FlexSearch introduce a new scoring mechanism called Contextual Search which incredibly boost up queries to a new level. The basic idea of this concept is to limit relevance by context instead of calculating relevance through the whole text distance. Imagine you add a short text block of some sentences to an index ID. Assuming the query includes a combination of first and last word from this text block, are they really relevant to each other? In this way contextual search also improves the results of relevance-based queries on large amount of text data.
Note: This feature is actually not enabled by default.
Workers get its own dedicated memory. Especially for larger indexes, web worker improves speed and available memory a lot. FlexSearch index was tested with a 250 Mb text file including 10 Million words. The indexing was done silently in background by multiple parallel running workers in about 7 minutes. The final index reserves ~ 8.2 Mb memory/space. The search result took ~ 0.25 ms.
Note: It is slightly faster to use no web worker when the index or query isn't too big (index < 500,000 words, query < 25 words).
Description | BulkSearch | FlexSearch |
Access | Read-Write optimized index | Read-Memory optimized index |
Memory | Large: ~ 5 Mb per 100,000 words | Tiny: ~ 100 Kb per 100,000 words |
Usecase |
|
|
Pagination | Yes | No |
Ranked Searching | No | Yes |
Contextual Index | No | Yes |
WebWorker | No | Yes |
<html>
<head>
<script src="js/flexsearch.min.js"></script>
</head>
...
Note: Use flexsearch.min.js for production and flexsearch.js for development.
Use latest from CDN:
<script src="https://cdn.rawgit.com/nextapps-de/flexsearch/master/flexsearch.min.js"></script>
npm install flexsearch
In your code include as follows:
var FlexSearch = require("flexsearch");
Or pass in options when requiring:
var index = require("flexsearch").create({/* options */});
AMD
var FlexSearch = require("./flexsearch.js");
Global methods:
Index methods:
FlexSearch.create(<options>)
var index = new FlexSearch();
alternatively you can also use:
var index = FlexSearch.create();
var index = new FlexSearch({
// default values:
encode: "icase",
mode: "forward",
multi: false,
async: false,
cache: false
});
Read more: Phonetic Search, Phonetic Comparison, Improve Memory Usage
Index.add_(id, string)
index.add(10025, "John Doe");
Index.search(string|options, <limit>, <callback>)
index.search("John");
Limit the result:
index.search("John", 10);
Perform queries asynchronously:
index.search("John", function(result){
// array of results
});
Index.update(id, string)
index.update(10025, "Road Runner");
Index.remove(id)
index.remove(10025);
index.reset();
index.destroy();
Index.init(<options>)
Note: Re-initialization will also destroy the old index!
Initialize (with same options):
index.init();
Initialize with new options:
index.init({
/* options */
});
FlexSearch.addMatcher({REGEX: REPLACE})
Add global matchers for all instances:
FlexSearch.addMatcher({
'ä': 'a', // replaces all 'ä' to 'a'
'ó': 'o',
'[ûúù]': 'u' // replaces multiple
});
Add private matchers for a specific instance:
index.addMatcher({
'ä': 'a', // replaces all 'ä' to 'a'
'ó': 'o',
'[ûúù]': 'u' // replaces multiple
});
Define a private custom encoder during creation/initialization:
var index = new FlexSearch({
encode: function(str){
// do something with str ...
return str;
}
});
FlexSearch.register(name, encoder)
FlexSearch.register('whitespace', function(str){
return str.replace(/ /g, '');
});
Use global encoders:
var index = new FlexSearch({ encode: 'whitespace' });
Private encoder:
var encoded = index.encode("sample text");
var encoded = FlexSearch.encode("whitespace", "sample text");
FlexSearch.register('mixed', function(str){
str = this.encode("icase", str); // built-in
str = this.encode("whitespace", str); // custom
return str;
});
FlexSearch.register('extended', function(str){
str = this.encode("custom", str);
// do something additional with str ...
return str;
});
index.info();
Returns information about the index, e.g.:
{
"bytes": 3600356288,
"id": 0,
"matchers": 0,
"size": 10000,
"status": false
}
Simply chain methods like:
var index = FlexSearch.create()
.addMatcher({'â': 'a'})
.add(0, 'foo')
.add(1, 'bar');
index.remove(0).update(1, 'foo').add(2, 'foobar');
Option | Values | Description |
mode |
"strict" "foward" "reverse" "ngram" "full" |
The indexing mode (tokenizer). |
encode |
false "icase" "simple" "advanced" "extra" function() | The encoding type. Choose one of the built-ins or pass a custom encoding function. |
cache |
true false | Enable/Disable caching. |
async |
true false | Enable/Disable asynchronous processing. |
worker |
false {number} | Enable/Disable and set count of running worker threads. |
depth |
false {number} | Enable/Disable contextual indexing and also sets relevance depth (experimental). |
Option | Description | Example | Memory Factor (n = length of word) |
"strict" | index whole words | foobar | * 1 |
"foward" | incrementally index words in forward direction | foobar foobar | * n |
"reverse" | incrementally index words in both directions | foobar foobar | * 2n |
"ngram" (default) | index words partially through phonetic n-grams | foobar foobar | * n/4 |
"full" | index every possible combination | foobar foobar | * n*(n-1) |
Option | Description | False-Positives | Compression |
false | Turn off encoding | no | no |
"icase" (default) | Case in-sensitive encoding | no | no |
"simple" | Phonetic normalizations | no | ~ 7% |
"advanced" | Phonetic normalizations + Literal transformations | no | ~ 35% |
"extra" | Phonetic normalizations + Soundex transformations | yes | ~ 60% |
function() | Pass custom encoding: function(string):string |
Reference String: "Björn-Phillipp Mayer"
Query | iCase | Simple | Advanced | Extra |
björn | yes | yes | yes | yes |
björ | yes | yes | yes | yes |
bjorn | no | yes | yes | yes |
bjoern | no | no | yes | yes |
philipp | no | no | yes | yes |
filip | no | no | yes | yes |
björnphillip | no | yes | yes | yes |
meier | no | no | yes | yes |
björn meier | no | no | yes | yes |
meier fhilip | no | no | yes | yes |
byorn mair | no | no | no | yes |
(false positives) | no | no | no | yes |
Note: The required memory depends on several options.
Encoding | Memory usage of every ~ 100,000 indexed words |
false | 260 kb |
"icase" (default) | 210 kb |
"simple" | 190 kb |
"advanced" | 150 kb |
"extra" | 90 kb |
Mode | Multiplied with: (n = average length of all words) |
"strict" | * 1 |
"forward" | * n |
"reverse" | * 2n |
"ngram" (default) | * n/4 |
"full" | * n*(n-1) |
Author FlexSearch: Thomas Wilkerling
License: Apache 2.0 License
FAQs
Next-Generation full text search library with zero dependencies.
The npm package flexsearch receives a total of 316,818 weekly downloads. As such, flexsearch popularity was classified as popular.
We found that flexsearch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.