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

未知
C/C++ JavaScript
Linux
2011-08-02
红薯

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 ferrets');
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

加载中

评论(0)

暂无评论

暂无资讯

暂无问答

Redis研究-3.5 Redis在OS上的安装

本文主要讲述一下Redis上的安装,实操一下。

2015/11/02 19:51
28
0
Redis的多线程与多进程

Redis的多线程与多进程

2016/05/23 18:06
226
2
GHD glattejern​ tidligere gruppe

Hair glatning im or her et hår style teknik, der anvendes siden 1890'erne involverer udfladning og glatning af hår intended for with present det en glat, strømlinet, og "sla...

2014/12/29 09:42
4
0
Thor: 'Tight-knit' Mets rotation tough to top

They like what LeBlanc showed coming back from the year he spent in Japan. In 14 starts for Triple-A Buffalo this past season, the 32-year-old posted a 1.71 ERA with 85 strikeou...

2016/12/16 16:58
4
0
使用etop查看系统中进程信息

Erlang提供了丰富的开发工具,你认为没有的时候,很可能是你不知道它存在. 在OS中,我们经常查看操作系统的进程信息,帮助我们进行诊断。 Erlang提供了一个小工具 etop (Erlang top), 用来查...

2011/11/23 14:09
176
0
Two wine seminars at the

Sommeliers share experience The Post and Courier Two wine seminars at the BB Charleston Wine + Food Festival filled glasses and raised knowledge for those who came to swirl and ...

2016/12/27 14:27
0
0
GHD fladjern tilbud​ af alle speed

Tresses glatning står et hår styling teknik, der anvendes siden 1890'erne involverer udfladning og glatning af hår regarding located at offer det en glat, strømlinet, og "s...

2014/12/29 09:38
2
0
Braves seize opportunity to get Jaime Garcia from

<p>For the last five seasons, big league players were prohibited from carrying tobacco products, including tins and packages, onto the field when fans were in the ballpark. But ...

2016/12/02 17:24
2
0

没有更多内容

加载失败,请刷新页面

返回顶部
顶部