微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Reds Redis加Node.js的全文搜索引擎

程序名称:Reds

授权协议: 未知

操作系统: Linux

开发语言: C/C++

Reds 介绍

Reds是由LearnBoost公司的TJ
Holowaychuk开发的一个基于RedisNode.js全文搜索引擎,其代码加上注释也只有300行。不得不说又是一个Redis的最佳实践,它的主要原理是通过Redis的sets数据结构将分词后的词语碎片进行存储。这里的分词仅仅是对英文按空格进行切分(中文分词就不要想了~)。

例子:
添加几个句子到搜索引擎中建立索引

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 @R_940_5023@s');
strs.push('Manny is a cat');
strs.push('Luna is a cat');
strs.push('Mustachio is a cat');

strs.forEach(function(str, i){ search.index(str, i); });

然后在Tobi dollars这个组合进行搜索

search.query(query = 'Tobi dollars', function(err, ids){
  if (err) throw err;
  console.log('Search results for "%s":', query);
  ids.forEach(function(id){
    console.log('  - %s', strs[id]);
  });
  process.exit();
});

下面是其搜索结果

Search results for "Tobi dollars":
  - Tobi wants four dollars

介绍内容来自:http://blog.nosqlfan.com/html/2676.html

Reds 官网

https://github.com/visionmedia/reds

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐