Gathering detailed insights and metrics for redredisearch
Gathering detailed insights and metrics for redredisearch
Gathering detailed insights and metrics for redredisearch
Gathering detailed insights and metrics for redredisearch
npm install redredisearch
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
98 Stars
151 Commits
24 Forks
8 Watching
1 Branches
1 Contributors
Updated on 12 Jul 2023
Minified
Minified + Gzipped
JavaScript (99.37%)
Makefile (0.63%)
Cumulative downloads
Total Downloads
Last day
-18.9%
43
Compared to previous day
Last week
2.6%
195
Compared to previous week
Last month
-17.7%
867
Compared to previous month
Last year
102.3%
11,588
Compared to previous year
RedRediSearch is a Node.js wrapper library for the RediSearch Redis module. It is more-or-less syntactically compatible with Reds, another Node.js search library. RedRediSearch and RediSearch can provide full-text searching that is much faster than the original Reds library (see Benchmarks).
If you are upgrading from Reds, you'll need to make your createSearch
asynchronous and re-index your data. Otherwise, your app-level logic and code should be compatible.
$ npm install redredisearch
The first thing you'll want to do is create a Search
instance, which allows you to pass a key
, used for namespacing within RediSearch so that you may have several searches in the same Redis database. You may specify your own node_redis instance with the redredisearch.setClient
function.
1redredisearch.createSearch('pets',{}, function(err, search) {
2 /* ... */
3});
You can then add items to the index with the Search#index
function.
1var strs = []; 2strs.push('Tobi wants four dollars'); 3strs.push('Tobi only wants $4'); 4strs.push('Loki is really fat'); 5strs.push('Loki, Jane, and Tobi are ferrets'); 6strs.push('Manny is a cat'); 7strs.push('Luna is a cat'); 8strs.push('Mustachio is a cat'); 9 10redredisearch.createSearch('pets',{}, function(err,search) { 11 strs.forEach(function(str, i){ search.index(str, i); }); 12});
To perform a query against the index simply invoke Search#query()
with a string, and pass a callback, which receives an array of ids when present, or an empty array otherwise.
1search 2 .query('Tobi dollars') 3 .end(function(err, ids){ 4 if (err) throw err; 5 console.log('Search results for "%s":', query); 6 ids.forEach(function(id){ 7 console.log(' - %s', strs[id]); 8 }); 9 });
By default, queries are an intersection of the search words. The previous example would yield the following output since only one string contains both "Tobi" and "dollars":
Search results for "Tobi dollars":
- Tobi wants four dollars
We can tweak the query to perform a union by passing either "union" or "or" to Search#type()
in redredisearch.search()
between Search#query()
and Search#end()
, indicating that any of the constants computed may be present for the id
to match.
1search 2 .query('tobi dollars') 3 .type('or') 4 .end(function(err, ids){ 5 if (err) throw err; 6 console.log('Search results for "%s":', query); 7 ids.forEach(function(id){ 8 console.log(' - %s', strs[id]); 9 }); 10 });
The union search would yield the following since three strings contain either "Tobi" or "dollars":
Search results for "tobi dollars":
- Tobi wants four dollars
- Tobi only wants $4
- Loki, Jane, and Tobi are ferrets
RediSearch has an advanced query syntax that can be used by using the 'direct' search type. See the RediSearch documentation for this syntax.
1search 2 .query('(hello|hella) (world|werld)') 3 .type('direct') 4 .end(function(err, ids){ 5 /* ... */ 6 });
Also included in the package is the RediSearch Suggestion API. This has no corollary in the Reds module. The Suggestion API is ideal for auto-complete type situations and is entirely separate from the Search API.
1var suggestions = redredisearch.suggestion('my-suggestion-list'); 2 3suggestions.add( 4 'redis', // add 'redis' 5 2, // with a 'score' of 2, this affects the position in the results, higher = higher up in results 6 function(err,sizeOfSuggestionList) { /* ... */ } // callback 7); 8suggestions.add( 9 'redisearch', 10 5, 11 function(err,sizeOfSuggestionList) { /* ... */ } 12); 13suggestions.add( 14 'reds', 15 1, 16 function(err,sizeOfSuggestionList) { /* ... */ } 17); 18 19/* ... */ 20 21sugggestions.get( 22 're', // prefix - will find anything starting with "re" 23 function(err, returnedSuggestions) { 24 /* returnedSuggestions is set to [ "redisearch", "redis", "reds" ] */ 25 } 26); 27 28sugggestions.get( 29 'redis', // prefix - will find anything starting with "redis", so not "reds" 30 function(err, returnedSuggestions) { 31 /* returnedSuggestions is set to [ "redisearch", "redis" ] */ 32 } 33)
There is also a fuzzy
opt and maxResults
that can either be set by chaining or by passing an object in the second argument in the constructor.
1redredisearch.createSearch(key, options, fn) : Search 2redredisearch.setClient(inClient) 3redredisearch.createClient() 4redredisearch.confirmModule(cb) 5redredisearch.words(str) : Array 6redredisearch.suggestionList(key,opts) : Suggestion 7Search#index(text, id[, fn]) 8Search#remove(id[, fn]); 9Search#query(text, fn[, type]) : Query 10Query#type(type) 11Query#between(str) 12Query#end(fn) 13Suggestion#fuzzy(isFuzzy) 14Suggestion#maxResults(maxResults) 15Suggestion#add(str,score,fn) 16Suggestion#get(prefix,fn) 17Suggestion#del(str,fn) 18
Examples:
1var search = redredisearch.createSearch('misc'); 2search.index('Foo bar baz', 'abc'); 3search.index('Foo bar', 'bcd'); 4search.remove('bcd'); 5search.query('foo bar').end(function(err, ids){});
When compared to Reds, RedRediSearch is much faster at indexing and somewhat faster at query:
Indexing - documents / second
Module | Tiny | Small | Medium | Large |
---|---|---|---|---|
Reds | 122 | 75 | 10 | 0 |
RediRediSearch | 1,256 | 501 | 132 | 5 |
Query - queries / second
Module | 1 term | 2 terms / AND | 2 terms / OR | 3 terms / AND | 3 terms / OR | Long* / AND | Long* / OR |
---|---|---|---|---|---|---|---|
Reds | 8,754 | 8,765 | 8,389 | 7,622 | 7,193 | 1,649 | 1,647 |
RedRediSearch | 10,955 | 12,945 | 10,054 | 12,769 | 8,389 | 6,456 | 12,311 |
The "Long" query string is taken from the Canadian Charter of Rights and Freedoms: "Everyone has the following fundamental freedoms: (a) freedom of conscience and religion; (b) freedom of thought, belief, opinion and expression, including freedom of the press and other media of communication; (c) freedom of peaceful assembly; and (d) freedom of association." (Used because I just had it open in another tab...)
(The MIT License)
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
Modified work Copyright (c) 2017 Kyle Davis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 6/21 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
54 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More