Installations
npm install redredisearch
Releases
Unable to fetch releases
Developer
stockholmux
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
6.11.0
NPM Version
5.1.0
Statistics
98 Stars
151 Commits
24 Forks
8 Watching
1 Branches
1 Contributors
Updated on 12 Jul 2023
Bundle Size
72.23 kB
Minified
16.40 kB
Minified + Gzipped
Languages
JavaScript (99.37%)
Makefile (0.63%)
Total Downloads
Cumulative downloads
Total Downloads
199,259
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
RedRediSearch
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).
Upgrading
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.
Installation
$ npm install redredisearch
Example
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.
API
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){});
Benchmarks
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...)
Next steps
- More coverage of RediSearch features
- Tests
- Better examples
License
(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
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/stockholmux/redredisearch/nodejs.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/stockholmux/redredisearch/nodejs.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
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
- Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 15 are checked with a SAST tool
Reason
54 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-gvcj-pfq2-wxj7
- Warn: Project is vulnerable to: GHSA-7fv9-m79r-j9x8
- Warn: Project is vulnerable to: GHSA-4w88-rjj3-x7wp
- Warn: Project is vulnerable to: GHSA-fjqr-fx3f-g4rv
- Warn: Project is vulnerable to: GHSA-6vrv-94jv-crrg
- Warn: Project is vulnerable to: GHSA-f9mq-jph6-9mhm
- Warn: Project is vulnerable to: GHSA-h9jc-284h-533g
- Warn: Project is vulnerable to: GHSA-m93v-9qjc-3g79
- Warn: Project is vulnerable to: GHSA-hvf8-h2qh-37m9
- Warn: Project is vulnerable to: GHSA-mpjm-v997-c4h4
- Warn: Project is vulnerable to: GHSA-3p22-ghq8-v749
- Warn: Project is vulnerable to: GHSA-77xc-hjv8-ww97
- Warn: Project is vulnerable to: GHSA-mq8j-3h7h-p8g7
- Warn: Project is vulnerable to: GHSA-p2jh-44qj-pf2v
- Warn: Project is vulnerable to: GHSA-p7v2-p9m8-qqg7
- Warn: Project is vulnerable to: GHSA-7x97-j373-85x5
- Warn: Project is vulnerable to: GHSA-7m48-wc93-9g85
- Warn: Project is vulnerable to: GHSA-qqvq-6xgj-jw8g
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-mpcf-4gmh-23w8
- Warn: Project is vulnerable to: GHSA-9qj9-36jm-prpv
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-wrvr-8mpx-r7pp
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-35q2-47q7-3pc3
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7
- Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.6
/10
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