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

chinese-search-dh

v1.1.10

Published

Chinese-Search is a full text search in chinese,base on nodejieba and redis,support to using sql pull data from mysql,and it is easy,small and fast.

Downloads

2

Readme

     ________    _                           _____                      __  
    / ____/ /_  (_)___  ___  ________       / ___/___  ____ ___________/ /_
   / /   / __ \/ / __ \/ _ \/ ___/ _ \______\__ \/ _ \/ __ `/ ___/ ___/ __ \
  / /___/ / / / / / / /  __(__  )  __/_____/__/ /  __/ /_/ / /  / /__/ / / /
  \____/_/ /_/_/_/ /_/\___/____/\___/     /____/\___/\__,_/_/   \___/_/ /_/

Build Status codecov Codacy Badge MIT Licence author

简介

Chinese-Search is a full text search in chinese,base on nodejieba and redis, support to using sql pull data from mysql, and it is easy, small and fast.

Chinese-Search 是一个全文检索组件,基层实现依赖nodejieba中文分词和redis存储。

修改介绍

由于原库长时间未更新,无法满足本人现阶段开发需求,故修改发布chinese-search-dh 目前新增redis密码功能,其他功能没有修改

安装


    npm i chinese-search-dh -s

测试


   npm i
   npm run test

使用


    ## ES5
    var search = require('chinese-search');

    ## ES6
    import search from 'chinese-search'

    var data = [{
        'name': 'C#权威指南-full',
        'title': 'C#权威指南是一本C#进阶学习最好的书籍。',
        'author':'ken',
        'id': 1
    }, {
        'name': 'C++权威指南-full',
        'title': 'A',
        'author':'ken',
        'id': 2
    }, {
        'name': 'PHP权威指南-full',
        'title': 'B',
        'author':'ken',
        'id': 3
    }]

    // [1]启动Redis服务,然后填入数据。
    const s = new search.Engine({
      cache:{
        host:'127.0.0.1',
        port:3679,
        type:'redis'
      }
    })

    s.cutKeys(['name','title'])   // 声明分词的KEY
    .initData(data,(err,r) => {
           if(err){
              console.error(err)
              return
           }
           // 全文检索
            s
             .returnKeys(['name','title','id']) // 声明数据返回包含KEY
             .query(['A'],(err,r)=>{            // 关键字数组
               if (err) {
                 console.error(err);
                      return
               };
                  console.log(r);   
                // 结果:[ { name: 'C++权威指南-full', title: 'A', id: 2 } ]
            })
    })
    // [2]启动Redis服务,mysql数据库,使用sql语句填入数据。
    let sql = 'select * from book'
    let opt = {cache:{
        'host': '127.0.0.1',
        'port': 6379
    },
    data:{
        host:'127.0.0.1',
        port:3306,
        db:'test',
        user:'root',
        pwd:'Ken5201314',
        type:'mysql'
    }}
    const s = new search.Engine(opt)
    s.cutKeys(['name','title'])
        .initData(sql,(err, r) => {
          if(err){
             console.error(err)
             return
          }
          // 全文检索
           s
            .returnKeys(['name','title','id']) // 声明数据返回包含KEY
            .query(['A'],(err,r)=>{            // 关键字数组
              if (err) {
                console.error(err);
                return
              };
                console.log(r);   
               // 结果:[ { name: 'C++权威指南-full', title: 'A', id: 2 } ]
           })
        })

API

cutKeys()


    // 声明分词的KEY,这步是必须的,否则报错
    s.cutKeys(['name','title'])

    // 假如被分词数据没有某个KEY,将略过
    s.cutKeys(['name','title','description'])

intData()


    var s = new search.Engine({'host':'127.0.0.1','port':4000})
            .cutKeys(['name','title'])   // 声明分词的KEY
            .initData(data,(err,r) => {      // data必须是个数组
                   if(err){
                        // 错误处理
                      return
                   }
                         // 正常在这里可以使用query()
                         //
                })

appendData()


    // 重声明分词的KEY并追加被检索数据
     s.cutKeys(['name']) // 重声明分词的KEY,非重声明则按照初始化设定
      .appendData([{
        'name': 'NodeJS权威指南',
        'title': 'NodeJS',
        'author':'ken',
        'id': 4
      }])

returnKeys()


     // 声明数据返回包含KEY
     s.returnKeys(['name','title','id'])
     .query(['A'],(err,r)=>{
        if (err) {
            console.log(err);
            return
        };
        // 结果:[ { name: 'AAA', title: 'A', id: 2 } ]
        console.log(r);   
    })

    // 声明数据返回包含KEY
    s.returnKeys(['name'])
     .query(['A'],(err,r)=>{
        if (err) {
            console.log(err);
            return
        };
        // 结果:[ { name: 'AAA' } ]
        console.log(r);   
    })

    // 没有声明数据返回包含KEY,则返回所有
    s.query(['A'],(err,r)=>{
        if (err) {
            console.log(err);
            return
        };
        // 结果:[ { name: 'AAA', title: 'A', id: 2}]
        console.log(r);   
    })

query()


    // 根据关键字数组查询
    s.query(['A','B'],(err,r)=>{
        if (err) {
            console.log(err);
            return
        };
        // 结果:[ { name: 'AAA', title: 'YYYYY', id: 2} } ,{ name: 'BBB', title: 'XXXXXX', id: 1}} ]
        console.log(r);   
    })

    // 根据关键字数组查询
    s.query(['A'],(err,r)=>{
        if (err) {
            console.log(err);
            return
        };
        // 结果:[ { name: 'AAA', title: 'YYYYY', id: 2} }]
        console.log(r);   
    })

author

author : chankamlam(Ken)

Email : [email protected]

license


   MIT