本文整理汇总了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");
}
示例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;
});
});
}
示例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);
});
}
示例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");
}
示例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
}
);
});
}