npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pickjunk/lookup

v1.1.4

Published

Tiny full-text search engine.

Downloads

16

Readme

lookup

微型 nodejs 中文全文搜索引擎

快速启动

import lookup from '@pickjunk/lookup';

const docs = [{
  id: '1',
  title: '百度真的不行',
  desc: '搜东西搜不出来'
}, {
  id: '2',
  title: '百度莆田',
  desc: '倒是很多结果'
}, {
  id: '3',
  title: '我是中国人',
  desc: '浓度过高'
}, {
  id: '4',
  title: '分词不在词库中',
  desc: '默认全分词,组合几个字也可以搜到'
}]

async function main() {
  // 实例化引擎
  const engine = lookup();
  // 加载词库
  await engine.dict('./dict.txt');

  // 进行文章索引
  for (let doc of docs) {
    engine.index(['title'], doc);
  }
  
  console.log(engine.search('baidu'));
  // [{
  //  id: '1',
  //  title: '百度真的不行',
  //  desc: '搜东西搜不出来'
  // }, {
  //  id: '2',
  //  title: '百度莆田',
  //  desc: '倒是很多结果'
  // }]
  
  console.log(engine.search('百度莆田'));
  // [{
  //  id: '2',
  //  title: '百度莆田',
  //  desc: '倒是很多结果'
  // }]
  
  console.log(engine.search('我'));
  // [{
  //  id: '3',
  //  title: '我是中国人',
  //  desc: '浓度过高'
  // }]
  
  console.log(engine.search('谷歌'));
  // []
  
  console.log(e.search('词在中'));
  // [{
  //  id: '4',
  //  title: '分词不在词库中',
  //  desc: '默认全分词,组合几个字也可以搜到'
  // }]
}

main();
// 词库 ./dict.txt
百度 2 brand|baidu 2 brand
baidu 莆田 2 desc
我是中国人 2 brand

API

代码以 typescript 写就,具体 API 可看编辑器的补全提示

特性

  • 支持同义词,在词库中同一行,用 | 分隔的多个词即为同义词
  • 支持词组的同义词联想,例如词典中定义了 百度baidu 为同义词,又定义了 百度网站 这个词,则引擎在构建字典树索引的时候,会自动生成一个 baidu网站 的词,作为 百度网站 的同义词
  • 默认全分词,零词典也能进行文章索引