tj / reds Goto Github PK
View Code? Open in Web Editor NEWlight-weight, insanely simple full text search module for node.js - backed by Redis
light-weight, insanely simple full text search module for node.js - backed by Redis
Is it possible to search using operators like AND, OR, -??
Example: 'cars and bikes', 'dogs or cats', 'bike -motorbike'
I did not find any example
Hi, I like this engine, small, powerful and smart.
I am only having one issue, it is when I apply the 'or' operator at the end of query, it is not taken into account:
Example:
function whipCream(caba) {
candysearch
.query(ingredients)
.end(function(err, candies){
if (err || candies.length == 0) {
console.log("Error with search for cream.", err);
return caba();
}
else {
var candy_count = candies.length, c=0;
(candy_count > limit) ? return_size = limit : return_size = candy_count;
candies.sort(function(a,b){return a-b});
while (c < return_size) {
mdb.hgetall("superhotcandy:"+candies[c]);
c++;
if (c == return_size) {
mdb.exec(function(error, sweetness) {
console.log(error);
return caba(sweetness);
});
}
}
}
}, 'or');
}
When searching for two words only returns if the algorithms match both words, not just one.
This code:
var strs = [];
strs.push('Tobi wants four dollars');
strs.push('Tobi only wants $4');
strs.push('Loki is really fat');
strs.push('Loki, Jane, and Tobi are ferrets');
strs.push('Manny is a cat');
strs.push('Luna is a cat');
strs.push('Mustachio is a cat');
const key = 'pets'
redsearch.createSearch(key, {}, (err, search) => {
search.remove("hola")
})
redsearch.createSearch(key, {}, (err, search) => {
if (err) console.log(err)
strs.forEach(function (str, i) { search.index(str, "hola"); });
});
redsearch.createSearch(key, {}, (err, search) => {
search
.query('cat* mus*')
.type('direct')
.end(function (err, ids) {
if (err) throw err;
ids.forEach(function (id) {
console.log(' - %s', id);
});
});
})
Drop this error when the index is not created (the fisrt time):
ReplyError: Index already exists. Drop it first!
at parseError (/srv/test/node_modules/redis-parser/lib/parser.js:193:12)
at parseType (/srv/test/node_modules/redis-parser/lib/parser.js:303:14) {
command: 'FT.CREATE',
args: [ 'pets', 'SCHEMA', 'payload', 'text' ]
}
I found some workaround grouping the callbacks:
...
const key = 'pets'
let cbks = []
function create(key, cbk) {
cbks.push(cbk)
if (cbks.length > 1) return;
redsearch.createSearch(key, {}, (err, search) => {
if (err) console.log(err)
for (let cll of cbks) {
cll(search)
}
cbks = []
})
}
create(key, (search) => {
search.remove("hola")
})
create(key, (search) => {
strs.forEach(function (str, i) { search.index(str, "hola"); });
})
create(key, (search) => {
search
.query('cat* mus*')
.type('direct')
.end(function (err, ids) {
if (err) throw err;
ids.forEach(function (id) {
console.log(' - %s', id);
});
});
})
This module, in my mind, is at stable state. It's quick, it works well generally and has a good number of depending modules (especially since it is used in Kue).
There is a lot that can be done with the basic structure and it can be monkey patched for extended functionality, but this comes with baggage and is not ideal. There have been a few good PRs that have requested extended and tweaked functionality but perhaps those PRs wouldn't make sense for all. I'm proposing keeping the functionality the same but making reds
more extensible and pluggable. I'd like to kick this process off by opening the floor to ideas on how to accomplish this in the most flexible and performant way.
My initial thoughts on the areas of plugablity:
The plugins could be introduced when creating the new search with an optional config object. It might look something like this:
var search = reds.createSearch('my-search', { indexRemovePlugin : myIndexRemovePlugin })
Thoughts on this idea? Have I missed something?
When I wanted to install red with npm install reds
I run into the following Error:
D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis>node "D:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\no
gyp.js" rebuild
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp info spawn python
gyp info spawn args [ 'D:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'msvs',
gyp info spawn args '-G',
gyp info spawn args 'msvs_version=auto',
gyp info spawn args '-I',
gyp info spawn args 'D:\\workspace_js\\node-track-file-changes\\node_modules\\reds\\node_modules\\redis\\node_modules\\hiredis\\build\\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'D:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\933\\.node-gyp\\0.10.20\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=C:\\Users\\933\\.node-gyp\\0.10.20',
gyp info spawn args '-Dmodule_root_dir=D:\\workspace_js\\node-track-file-changes\\node_modules\\reds\\node_modules\\redis\\node_modules\\hiredis',
gyp info spawn args '--depth=.',
gyp info spawn args '--generator-output',
gyp info spawn args 'D:\\workspace_js\\node-track-file-changes\\node_modules\\reds\\node_modules\\redis\\node_modules\\hiredis\\build',
gyp info spawn args '-Goutput_dir=.' ]
gyp info spawn C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args '/clp:Verbosity=minimal',
gyp info spawn args '/nologo',
gyp info spawn args '/p:Configuration=Release;Platform=x64' ]
Die Projekte in dieser Projektmappe werden nacheinander erstellt. Um eine parallele Erstellung zu ermöglichen, müssen Sie den Schalter "/m" hinzufügen.
hiredis.c
async.c
net.c
sds.c
..\..\deps\hiredis\net.c(35): fatal error C1083: Cannot open include file: 'sys/socket.h': No such file or directory [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node
_modules\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\hiredis.c(35): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node
_modules\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\async.c(35): fatal error C1083: Cannot open include file: 'strings.h': No such file or directory [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_
modules\hiredis\build\deps\hiredis.vcxproj]
d:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\deps\hiredis\sds.h(45): error C2054: expected '(' to follow 'inline' (..\..\deps\hiredis\sds.c) [D:\w
orkspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\build\deps\hiredis.vcxproj]
d:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\deps\hiredis\sds.h(45): error C2085: 'sdslen' : not in formal parameter list (..\..\deps\hiredis\sds.
c) [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\build\deps\hiredis.vcxproj]
d:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\deps\hiredis\sds.h(45): error C2143: syntax error : missing ';' before '{' (..\..\deps\hiredis\sds.c)
[D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\build\deps\hiredis.vcxproj]
d:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\deps\hiredis\sds.h(50): error C2054: expected '(' to follow 'inline' (..\..\deps\hiredis\sds.c) [D:\w
orkspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\build\deps\hiredis.vcxproj]
d:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\deps\hiredis\sds.h(50): error C2085: 'sdsavail' : not in formal parameter list (..\..\deps\hiredis\sd
s.c) [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\build\deps\hiredis.vcxproj]
d:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\deps\hiredis\sds.h(50): error C2143: syntax error : missing ';' before '{' (..\..\deps\hiredis\sds.c)
[D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(53): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\
hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(83): warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\no
de_modules\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(104): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(122): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(123): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(135): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(136): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(157): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(158): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(179): warning C4013: 'va_copy' undefined; assuming extern returning int [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis\bui
ld\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(214): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(215): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(225): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(229): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(237): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(245): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(246): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules
\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(251): warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\n
ode_modules\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(257): warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\n
ode_modules\hiredis\build\deps\hiredis.vcxproj]
..\..\deps\hiredis\sds.c(270): warning C4267: 'return' : conversion from 'size_t' to 'int', possible loss of data [D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_mo
dules\hiredis\build\deps\hiredis.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (D:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "D:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis
gyp ERR! node -v v0.10.20
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm info [email protected] Failed to exec install script
npm info D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis\node_modules\hiredis unbuild
npm info preuninstall [email protected]
npm info uninstall [email protected]
npm info postuninstall [email protected]
npm WARN optional dep failed, continuing [email protected]
npm info build D:\workspace_js\node-track-file-changes\node_modules\reds\node_modules\redis
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
npm info build D:\workspace_js\node-track-file-changes\node_modules\reds
npm info linkStuff [email protected]
npm info install [email protected]
npm info postinstall [email protected]
[email protected] node_modules\reds
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected]
npm info ok
System: Windows7 (64 Bit)
Node: v0.10.20
Edited: Ah ok its the hiredis
modul that makes problem.
Reason: package.json requires node to be < 0.7.0
Looks to me that 81ea212 has not been published to npm. I'd love to get multiple keywords working without circumventing npm. Can this get published?
Hey TJ,
I'm using mocha to test some code that uses reds. It fails due to a leak of 'result'. The error is in the component natural, which you have pinned to version 0.0.27. It looks like later versions of natural have undergone significant refactoring, so I couldn't quickly tell whether later versions have fixed the leak. But you may be sticking with 0.0.27 because of API changes.
I'll disable the warning of the leak of 'result' on the mocha command line, which should be all I need for now. But I thought you should at least be aware of this issue.
Jim
I'd like to connect to my redis server that lives on another box. I see in the redis plugin you can pass the host in when you call redis.createClient(port, host, options)
What I am trying to figure out is what the best way to do this would be for reds. Excited to kick the tires.
Hi, I was wondering if I could get an example of how to make a search index in something other than Redis. Specifically I'm hoping to put the index data into a normal Javascript object.
I see that I need to override reds.createClient(), and that the object that is returned needs to implement a multi() function and zrevrangebyscore() function. But I don't know exactly what those functions should do, or if the object needs implement anything else.
Thanks for you help!
for pagination etc
Hello,
I am having trouble installing reds on windows 8. When I run "npm install reds", I get the following error:
C:\...\node_modules\reds\node_modules\redis\node_modules\hiredis\build\bindings.sln:
Solution file error MSB5004: The solution file has two projects named "hiredis".
For example ,index three words "abcde","bcdefg","abcd". Then i search "abc" get the result "abcde" "abcd" or when i search "cde" get the result "abcde" "bcdefg"
I want this to support Chinese.How can I do it ?
this is used by kue. redis is super old and requires hiredis. hiredis doesn't support iojs. i want to upgrade to iojs, but my app currently uses kue. my life sucks. plz unpin redis so at least hiredis is not included.
thx :D
If I have the word Michael Clarke indexed and search for this term using
M
Mi
Mic (returns result)
Mich
Micha
Michae
Michael
Michael C
Michael Cl
Michael Cla
Michael Clar
Michael Clark (returns result)
Michael Clarke (returns result)
should return Michael Clarke I am assuming, much like what happens in Facebook search.
However, that is not the case.
When I enter have Mic, Michael Clarke is returned when I add one more letter i.e. Mich nothing is returned; I would have to enter the full name Michael for it to be returned again.
Further to that nothing is returned until I type Michael Clark.
Is this how reds suppose to work, is there a set of options I can change to "tweek" this behavior?
allowing for priority
Natural 0.1.17 removes global scoped variables which fail Mocha tests :)
The docs say:
We can tweak reds to perform a union by passing either "union" or "or" to reds.search() after the callback, indicating that any of the constants computed may be present for the id to match.
and show this in the following example. However looking at the code I can't see how this can work. Further it appears as though query(..).type('or').end(..) is the way to perform an 'or' search.
Related to the type() function is between() which also isn't documented.
throw err;
^
TypeError: Cannot read property 'length' of null
at Object.exports.stripStopWords (/var/www/dev/public_html/baris/node-forum/node_modules/reds/lib/reds.js:113:42)
at Search.index (/var/www/dev/public_html/baris/node-forum/node_modules/reds/lib/reds.js:282:36)
at /var/www/dev/public_html/baris/node-forum/src/posts.js:425:14
at /var/www/dev/public_html/baris/node-forum/src/posts.js:141:5
at try_callback (/var/www/dev/public_html/baris/node-forum/node_modules/redis/index.js:532:9)
at RedisClient.return_reply (/var/www/dev/public_html/baris/node-forum/node_modules/redis/index.js:614:13)
at ReplyParser.<anonymous> (/var/www/dev/public_html/baris/node-forum/node_modules/redis/index.js:266:14)
at ReplyParser.EventEmitter.emit (events.js:95:17)
at ReplyParser.send_reply (/var/www/dev/public_html/baris/node-forum/node_modules/redis/lib/parser/javascript.js:300:10)
at ReplyParser.execute (/var/www/dev/public_html/baris/node-forum/node_modules/redis/lib/parser/javascript.js:203:22)
DEBUG: Program node app exited with code 8
exports.words returns null if it is passed "<-- ."
.
PROJECT: https://github.com/stockholmux/redredisearch
This code:
var strs = [];
strs.push('Tobi wants four dollars');
strs.push('Tobi only wants $4');
strs.push('Loki is really fat');
strs.push('Loki, Jane, and Tobi are ferrets');
strs.push('Manny is a cat');
strs.push('Luna is a cat');
strs.push('Mustachio is a cat');
const key = 'pets'
redsearch.createSearch(key, {}, (err, search) => {
search.remove("hola")
})
redsearch.createSearch(key, {}, (err, search) => {
if (err) console.log(err)
strs.forEach(function (str, i) { search.index(str, "hola"); });
});
redsearch.createSearch(key, {}, (err, search) => {
search
.query('cat* mus*')
.type('direct')
.end(function (err, ids) {
if (err) throw err;
ids.forEach(function (id) {
console.log(' - %s', id);
});
});
})
Drop this error when the index is not created (the fisrt time):
ReplyError: Index already exists. Drop it first!
at parseError (/srv/test/node_modules/redis-parser/lib/parser.js:193:12)
at parseType (/srv/test/node_modules/redis-parser/lib/parser.js:303:14) {
command: 'FT.CREATE',
args: [ 'pets', 'SCHEMA', 'payload', 'text' ]
}
I found some workaround grouping the callbacks:
...
const key = 'pets'
let cbks = []
function create(key, cbk) {
cbks.push(cbk)
if (cbks.length > 1) return;
redsearch.createSearch(key, {}, (err, search) => {
if (err) console.log(err)
for (let cll of cbks) {
cll(search)
}
cbks = []
})
}
create(key, (search) => {
search.remove("hola")
})
create(key, (search) => {
strs.forEach(function (str, i) { search.index(str, "hola"); });
})
create(key, (search) => {
search
.query('cat* mus*')
.type('direct')
.end(function (err, ids) {
if (err) throw err;
ids.forEach(function (id) {
console.log(' - %s', id);
});
});
})
This is needed to use HEAD of kue in environments where redis doesn't live on the same machine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.