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

lunr-chinese

v1.2.0

Published

Lunr with chinese support, do words segment with nodejieba locally.

Downloads

42

Readme

lunr-chinese

Lunr addon, do words segment with nodejieba locally.

Description

Build based on lunr v0.72 and nodejieba, add chinese tokenize and search available to lunr.

The lib not use the lunr v2+ is for the lunr v2+ changes the tokenize method mainly, and which is an improve of the performance for English only, not suitable for Chinese.

new method lunr.init(idx, data, path)

return lunr instance with generated lunr index lunr.init(generatedIndex)
return lunr instance with lunr.init(idx, data(array))
generate lunr index into file lunr.init(idx, data(array), path)

search with lunrInstance.search('例子')

Install

npm i lunr-chinese --save-dev

For front-end use the build file lunr-chinese, lunr-chinese.min.js in the project, which will return the lunr instance for use.

Usage

const lunr = require('lunr-chinese')()

let idx = lunr(function() {
  this.ref('id')

  this.field('title', { boost: 10 })
  this.field('categories')
  this.field('body')
})

const postContents = contents.map(content => idx.add(content))

// get the Lunr instance(use locally)
const lunrCn = lunr.init(idx, postContents)
lunrCn.search('例子')

// generate the Lunr Index file
lunr.init(idx, postContents, 'path/lunrCnIndexs.json')

Load and work with generated index file.

// load `lunr` from lunr-chinese.js

var lunrCnIndexs = JSON.parse(lunrCnIndexsString)
var chineseLunr = lunr.init(lunrCnIndexs)

chineseLunr.search('例子')

To use custom dictionary like this

const lunr = require('lunr-chinese')({
  dict: nodejieba.DEFAULT_DICT,
  hmmDict: nodejieba.DEFAULT_HMM_DICT,
  userDict: './test/testdata/userdict.utf8',
  idfDict: nodejieba.DEFAULT_IDF_DICT,
  stopWordDict: nodejieba.DEFAULT_STOP_WORD_DICT,
  method: 'cutForSearch' //optional [default is `cut`] (call the specific method for `nodejieba`)
});

Method values

'小明硕士毕业于中国科学院计算所'

  • cut: [ '小明', '硕士', '毕业', '于', '中国科学院', '计算所' ]
  • cutAll: [ '小', '明', '硕士', '毕业', '于', '中国', '中国科学院', '科学', '科学院', '学院', '计算', '计算所' ]
  • cutHMM: [ '小明', '硕士', '毕业于', '中国', '科学院', '计算', '所' ]
  • cutForSearch: [ '小明', '硕士', '毕业', '于', '中国', '科学', '学院', '科学院', '中国科学院', '计算', '计算所' ]
  • cutSmall: [ '小', '明', '硕', '士', '毕', '业', '于', '中', '国', '科', '学', '院', '计', '算', '所' ]

examples

an example of the custom doc file

抹茶 n
星冰乐 n
拿铁 n

for more details check CppJieba 字典