日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Elasticlunr.js 简单介绍

發(fā)布時(shí)間:2025/7/14 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Elasticlunr.js 简单介绍 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Elasticlunr.js

項(xiàng)目地址:http://elasticlunr.com/
代碼地址:https://github.com/weixsong/elasticlunr.js
文檔地址:http://elasticlunr.com/docs/index.html

Elasticlurn.js is a lightweight full-text search engine in Javascript for browser search and offline search.
Elasticlunr.js is developed based on Lunr.js, but more flexible than lunr.js. Elasticlunr.js provides Query-Time boosting and field search.
Elasticlunr.js is a bit like Solr, but much smaller and not as bright, but also provide flexible configuration and query-time boosting.

Key Features Comparing with Lunr.js

  • Query-Time boosting, you don’t need to setup boosting weight in index building procedure, this make it more flexible that you could try different boosting scheme.
  • More rational scoring mechanism, Elasticlunr.js use quite the same scoring mechanism as Elasticsearch, and also this scoring mechanism is used by lucene.
  • Field-search, you could choose which field to index and which field to search.
  • Boolean Model, you could set which field to search and the boolean model for each query token, such as “OR”, “AND”.
  • Combined Boolean Model, TF/IDF Model and the Vector Space Model, make the results ranking more reliable.
  • Fast, Elasticlunr.js removed TokenCorpus and Vector from lunr.js, by using combined model there is no need to compute the vector of a document and query string to compute similarity of query and matched document, this improve the search speed significantly.
  • Small index file, Elasticlunr.js did not store TokenCorpus because there is no need to compute query vector and document vector, then the index file is very small, this is especially helpful when elasticlurn.js is used as offline search.

Example

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

var index = elasticlunr(function () {this.addField('title');this.addField('body');this.setRef('id'); });

Adding documents to the index is as simple as:

var doc1 = {"id": 1,"title": "Oracle released its latest database Oracle 12g","body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year." }var doc2 = {"id": 2,"title": "Oracle released its profit report of 2015","body": "As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle's profit of 2015 reached 12.5 Billion." }index.addDoc(doc1); index.addDoc(doc2);

Then searching is as simple:

index.search("Oracle database profit");

Also, you could do query-time boosting by passing in a configuration.

index.search("Oracle database profit", {fields: {title: {boost: 2},body: {boost: 1}} });

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

[{"ref": 1,"score": 0.5376053707962494 }, {"ref": 2,"score": 0.5237481076838757 }]

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

Description

Elasticlunr.js is developed based on Lunr.js, but more flexible than lunr.js. Elasticlunr.js provides Query-Time boosting and field search.
A bit like Solr, but much smaller and not as bright, but also provide flexible configuration and query-time boosting.

Why

  • In some system, you don’t want to deploy any Web Server(such as Apache, Nginx, etc.), you only provide some static web pages and provide search function in client side. Then you could build index in previous and load index in client side.
  • Provide offline search functionality. For some documents, user usually download these documents, you could build index and put index in the documents package, then provide offline search functionality.
  • For some limited or restricted network, such WAN or LAN, offline search is a better choice.
  • For mobile device, Iphone or Android phone, network traffic maybe very expensive, then provide offline search is a good choice.
  • Installation

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

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

    Documentation

    This part only contain important apects of elasticlunr.js, for the whole documentation, please go to API documentation.

    1. Build Index

    When you first create a index instance, you need to specify which field you want to index. If you did not specify which field to index, then no field will be searchable for your documents.
    You could specify fields by:

    var index = elasticlunr(function () {this.addField('title');this.addField('body');this.setRef('id'); });

    You could also set the document reference by this.setRef('id'), if you did not set document ref, elasticlunr.js will use ‘id’ as default.

    You could do the above index setup as followings:

    var index = elasticlunr(); index.addField('title'); index.addField('body'); index.setRef('id');

    Default supported language of elasticlunr.js is English, if you want to use elasticlunr.js to index other language documents, then you need to use elasticlunr.js combined with lunr-languages.
    Assume you’re using lunr-language in Node.js envrionment, you could import lunr-language as followings:

    var lunr = require('./lib/lunr.js'); require('./lunr.stemmer.support.js')(lunr); require('./lunr.de.js')(lunr);var idx = lunr(function () {// use the language (de)this.use(lunr.de);// then, the normal lunr index initializationthis.field('title')this.field('body') });

    For more details, please go to lunr-languages.

    2. Add document to index

    Add document to index is very simple, just prepare you document in JSON format, then add it to index.

    var doc1 = {"id": 1,"title": "Oracle released its latest database Oracle 12g","body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year." }var doc2 = {"id": 2,"title": "Oracle released its profit report of 2015","body": "As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle's profit of 2015 reached 12.5 Billion." }index.addDoc(doc1); index.addDoc(doc2);

    If your JSON document contains field that not configured in index, then that field will not be indexed, which means that field is not searchable.

    3. Remove document from index

    Elasticlunr.js support remove a document from index, just provide JSON document to elasticlunr.Index.prototype.removeDoc() function.

    For example:

    var doc = {"id": 1,"title": "Oracle released its latest database Oracle 12g","body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year." }index.removeDoc(doc);

    Remove a document will remove each token of that document’s each field from field-specified inverted index.

    4. Update a document in index

    Elasticlunr.js support update a document in index, just provide JSON document to elasticlunr.Index.prototype.update() function.

    For example:

    var doc = {"id": 1,"title": "Oracle released its latest database Oracle 12g","body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year." }index.update(doc);

    5. Query from Index

    Elasticlunr.js provides flexible query configuration, supports query-time boosting and Boolean logic setting.
    You could setup a configuration tell elasticlunr.js how to do query-time boosting, which field to search in, how to do the boolean logic.
    Or you could just use it by simply provide a query string, this will aslo works perfectly because the scoring mechanism is very efficient.

    5.1 Simple Query

    Because elasticlunr.js has a very perfect scoring mechanism, so for most of your requirement, simple search would be easy to meet your requirement.

    index.search("Oracle database profit");

    Output is a results array, each element of results array is an Object contain a ref field and a score field.
    ref is the document reference.
    score is the similarity measurement.

    Results array is sorted descent by score.

    5.2 Configuration Query

    5.2.1 Query-Time Boosting

    Setup which fields to search in by passing in a JSON configuration, and setup boosting for each search field.
    If you setup this configuration, then elasticlunr.js will only search the query string in the specified fields with boosting weight.

    The scoring mechanism used in elasticlunr.js is very complex, please goto details for more information.

    index.search("Oracle database profit", {fields: {title: {boost: 2},body: {boost: 1}} });

    5.2.2 Boolean Model

    Elasticlunr.js also support boolean logic setting, if no boolean logic is setted, elasticlunr.js use “OR” logic defaulty. By “OR” default logic, elasticlunr.js could reach a high Recall.

    index.search("Oracle database profit", {fields: {title: {boost: 2},body: {boost: 1}},boolean: "OR" });

    Boolean operation is performed based on field. This means that if you choose “AND” logic, documents with all the query tokens in the query field will be returned as a field results. If you query in multiple fields, different field results will be merged together to give a final query results.

    總結(jié)

    以上是生活随笔為你收集整理的Elasticlunr.js 简单介绍的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 亚洲射图 | 成人a毛片久久免费播放 | 一吻定情2013日剧 | 日韩综合在线观看 | 97免费在线视频 | 欧美性视频播放 | 成年人黄色网址 | 激情欧美日韩 | 日韩高清在线观看一区 | 欧美亚洲综合另类 | 中文字幕丝袜诱惑 | 综合久久一区 | 国内精久久久久久久久久人 | 四虎影院www | 免费视频网站www | 亚洲av成人精品日韩在线播放 | 爆操白虎逼| 婷婷狠狠干 | 青青草自拍视频 | 深夜福利网站在线观看 | 天堂一区二区三区四区 | 夜间福利视频 | 日本人妻熟妇久久久久久 | 老牛av一区二区 | 国产乱码一区二区三区 | 日韩在线播放视频 | 日韩视频中文字幕 | 美女张开腿流出白浆 | 婷婷伊人久久 | 自拍偷拍21p| 一区二区三区高清在线观看 | 蜜桃精品久久久久久久免费影院 | 黑人糟蹋人妻hd中文字幕 | 伦伦影院午夜理伦片 | 亚洲精品日韩精品 | 国产精品女人久久久 | 国产视频手机在线播放 | 图片区视频区小说区 | 真人抽搐一进一出视频 | 中文字幕五区 | 亚洲涩涩涩 | 日韩伊人网 | 久久久无码精品亚洲国产 | 亚洲国产91 | 日本理论片午伦夜理片在线观看 | 亚洲系列 | 超碰在线小说 | 佐佐木明希电影 | 好吊色在线视频 | 男生尿隔着内裤呲出来视频 | 91资源站 | 欧美日韩在线一区二区 | 亚洲高清在线看 | 久久成人一区 | 精品国产乱码久久久久久108 | 天天综合网在线 | 天天av天天 | 饥渴少妇勾引水电工av | 少妇床戏av| 成人免费视频久久 | 亚洲视频免费在线观看 | 国产自产视频 | 日韩性xxxx| 精品日韩一区 | av无毛| 亚洲欧洲久久久 | brazzers欧美一区二区 | 光溜溜视频素材大全美女 | 日韩色网| mm1313亚洲国产精品无码试看 | 捆绑中国女人hd视频 | 日日日人人人 | 91精品婷婷国产综合久久竹菊 | 台湾男男gay做爽爽的视频 | 四虎4hu永久免费网站影院 | av网站大全在线观看 | 淫五月 | 亚洲一区不卡在线 | 国产免费不卡视频 | 91久久免费 | 国产传媒第一页 | 无码一区二区波多野结衣播放搜索 | a毛片视频 | 亚洲美免无码中文字幕在线 | 午夜福利啪啪片 | 欧美乱三级 | 欧美一级无毛 | 韩国性经典xxxxhd | 亚洲国产精彩视频 | 日本h在线观看 | 91啪国产在线 | 黄色一级视频免费 | 国产情侣在线播放 | 99er在线| 国产精品一区在线观看 | 国产一区二区三区黄片 | 日韩精品久久久久久久酒店 | 亚洲永久在线 | 国产拍拍拍拍拍拍拍拍拍拍拍拍拍 |