當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript lunr類代碼示例

本文整理匯總了TypeScript中lunr的典型用法代碼示例。如果您正苦於以下問題:TypeScript lunr類的具體用法?TypeScript lunr怎麽用?TypeScript lunr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了lunr類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: basic_test

function basic_test() {
    const index = lunr(function() {
        this.field("title");
        this.field("body");
        this.field("content", {
            boost: 2,
            extractor: (doc: object) => "oof"
        });
        this.ref("id");
        this.add({
            id: 1,
            title: "Foo",
            body: "Foo foo foo!"
        },
        {
            boost: 2
        });
        this.add({
            id: 2,
            title: "Bar",
            body: "Bar bar bar!"
        });
    });

    index.search("foo");
}
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:26,代碼來源:lunr-tests.ts

示例2: pipeline_test

function pipeline_test() {
    const index = lunr(function() {
        this.pipeline.add((token, tokenIndex, tokens) => {
            // text processing in here
            return token;
        });

        this.pipeline.after(lunr.stopWordFilter, (token, tokenIndex, tokens) => {
            // text processing in here
            return token;
        });
    });
}
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:13,代碼來源:lunr-tests.ts

示例3: createIndex

// Create the lunr index - the docs should be an array of objects, each object containing
// the path and search terms for a page
function createIndex(loadIndex: IndexLoader): lunr.Index {
  // The lunr typings are missing QueryLexer so we have to add them here manually.
  const queryLexer = (lunr as any as { QueryLexer: { termSeparator: RegExp } }).QueryLexer;
  queryLexer.termSeparator = lunr.tokenizer.separator = /\s+/;
  return lunr(/** @this */function () {
    this.ref('path');
    this.field('titleWords', { boost: 10 });
    this.field('headingWords', { boost: 5 });
    this.field('members', { boost: 4 });
    this.field('keywords', { boost: 2 });
    loadIndex(this);
  });
}
開發者ID:alxhub,項目名稱:angular,代碼行數:15,代碼來源:search-worker.ts

示例4: basic_test

function basic_test() {
    const index = lunr(function() {
        this.field("title");
        this.field("body");
        this.ref("id");
        this.add({
            id: 1,
            title: "Foo",
            body: "Foo foo foo!"
        });
        this.add({
            id: 2,
            title: "Bar",
            body: "Bar bar bar!"
        });
    });

    index.search("foo");
}
開發者ID:DenisCarriere,項目名稱:DefinitelyTyped,代碼行數:19,代碼來源:lunr-tests.ts

示例5: basic_test

function basic_test() {
    const index = lunr(function() {
        this.field("title");
        this.field("body");
        this.field("content", {
            boost: 2,
            extractor: (doc: object) => "oof"
        });
        this.ref("id");
        this.add({
            id: 1,
            title: "Foo",
            body: "Foo foo foo!"
        },
        {
            boost: 2
        });
        this.add({
            id: 2,
            title: "Bar",
            body: "Bar bar bar!"
        });
    });

    index.search("foo");

    index.query(q => {
        q.term(
            lunr.tokenizer('search terms'),
            {
                wildcard: lunr.Query.wildcard.TRAILING,
                presence: lunr.Query.presence.REQUIRED
            }
        );
    });
}
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:36,代碼來源:lunr-tests.ts


注:本文中的lunr類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。