Code Monkey home page Code Monkey logo

lunr.js's Introduction

更好的方案: MihaiValentin/lunr-languages#53

Maybe a better one: MihaiValentin/lunr-languages#53


Use a node module to index the document content, if you want to use this in a browser,index documents in command line, dump lunr index object to a file and use that file to init lunr.js in browser, the file may be very large if the document is large.

使用nodejs库 nodejieba 来分词,nodejieba本身是对c++库的封装,所以安装这个模块的时候需要c++环境

如果需要在前端使用搜索功能,需要先在后端处理文件,把索引保存成json格式,然后在前端引用

最初只是为了替换 gitbook 中的lunr依赖

注意:没有补全对应的测试用例


Lunr.js

Join the chat at https://gitter.im/olivernn/lunr.js

Build Status

A bit like Solr, but much smaller and not as bright.

Example

A very simple search index can be created using the following:

var idx = lunr(function () {
    this.field('title', { boost: 10 })
    this.field('body')
})

Adding documents to be indexed is as simple as:

var doc = {
    "title": "黄金时代",
    "body": "那一天我二十一岁,在我一生的黄金时代,我有好多奢望。我想爱,想吃,还想在一瞬间变成天上半明半暗的云。后来我才知道,生活就是个缓慢受锤的过程,人一天天老下去,奢望也一天天消失,最后变得像挨了锤的牛一样。可是我过二十一岁生日时没有预见到这一点。我觉得自己会永远生猛下去,什么也锤不了我。",
    "author": "王小波",
    "id": 1
}
idx.add(doc)

Then searching is as simple:

idx.search("生活")

This returns a list of matching documents with a score of how closely they match the search query:

[{
    "ref": 1,
    "score": 0.0011097036390631915
}]

API documentation is available, as well as a full working example.

Description

Lunr.js is a small, full-text search library for use in the browser. It indexes JSON documents and provides a simple search interface for retrieving documents that best match text queries.

Why

For web applications with all their data already sitting in the client, it makes sense to be able to search that data on the client too. It saves adding extra, compacted services on the server. A local search index will be quicker, there is no network overhead, and will remain available and useable even without a network connection.

Installation

Simply include the lunr.js source file in the page that you want to use it. Lunr.js is supported in all modern browsers.

Browsers that do not support ES5 will require a JavaScript shim for Lunr to work. You can either use Augment.js, ES5-Shim or any library that patches old browsers to provide an ES5 compatible JavaScript environment.

Contributing

See the CONTRIBUTING.mdown file.

lunr.js's People

Contributors

olivernn avatar codepiano avatar benpickles avatar richardpoole avatar cvan avatar piranna avatar nolanlawson avatar weixsong avatar janeisklar avatar d0ugal avatar gregglind avatar jakiestfu avatar jaylett avatar kkirsche avatar mamboer avatar lvivier avatar rushton avatar pborreli avatar kix avatar gitter-badger avatar tony-jacobs avatar mihaivalentin avatar bvaughn avatar eiriksm avatar jkellerer avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.