How to use the lunr.Builder function in lunr

To help you get started, we’ve selected a few lunr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitwarden / jslib / src / services / search.service.ts View on Github external
async indexCiphers(): Promise {
        if (this.indexing) {
            return;
        }
        // tslint:disable-next-line
        console.time('search indexing');
        this.indexing = true;
        this.index = null;
        const builder = new lunr.Builder();
        builder.ref('id');
        (builder as any).field('shortid', { boost: 100, extractor: (c: CipherView) => c.id.substr(0, 8) });
        (builder as any).field('name', { boost: 10 });
        (builder as any).field('subtitle', {
            boost: 5,
            extractor: (c: CipherView) => {
                if (c.subTitle != null && c.type === CipherType.Card) {
                    return c.subTitle.replace(/\*/g, '');
                }
                return c.subTitle;
            },
        });
        builder.field('notes');
        (builder as any).field('login.username', {
            extractor: (c: CipherView) => c.type === CipherType.Login && c.login != null ? c.login.username : null,
        });
github Soluto / tweek / services / authoring / src / search-index / build / build.js View on Github external
module.exports = function createIndex(repoDir) {
  const path = require('path');
  const promisify = require('util').promisify;
  const glob = promisify(require('glob'));
  const { Observable } = require('rxjs');
  const _ = require('highland');
  const readFile = _.wrapCallback(require('fs').readFile);
  const lunr = require('lunr');
  const R = require('ramda');

  const builder = new lunr.Builder();
  builder.pipeline.add(lunr.trimmer, lunr.stemmer);
  builder.searchPipeline.add(lunr.stemmer);
  builder.tokenizer.separator = /(?:[_/]|\s|-)/;

  builder.ref('id');
  builder.field('id');
  builder.field('description');
  builder.field('tags');
  builder.field('name');

  function mapToLower(obj) {
    return R.map(R.ifElse(R.is(String), R.toLower, mapToLower))(obj);
  }

  return glob(path.join(repoDir, 'manifests/**/*.json'))
    .catch(console.error)
github Redocly / redoc / src / services / SearchWorker.worker.ts View on Github external
score: number;
}

let store: any[] = [];

let resolveIndex: (v: lunr.Index) => void = () => {
  throw new Error('Should not be called');
};

const index: Promise = new Promise(resolve => {
  resolveIndex = resolve;
});

lunr.tokenizer.separator = /\s+/;

const builder = new lunr.Builder();
builder.field('title');
builder.field('description');
builder.ref('ref');

builder.pipeline.add(lunr.trimmer, lunr.stopWordFilter, lunr.stemmer);

const expandTerm = term => '*' + lunr.stemmer(new lunr.Token(term, {})) + '*';

export function add(title: string, description: string, meta?: T) {
  const ref = store.push(meta) - 1;
  const item = { title: title.toLowerCase(), description: description.toLowerCase(), ref };
  builder.add(item);
}

export async function done() {
  resolveIndex(builder.build());
github stanford-oval / almond-cloud / build / build-doc-index.js View on Github external
async function main() {
    const builder = new lunr.Builder();  
    builder.field('title', { boost: 2 });
    builder.field('page_title');
    builder.field('content');
    builder.ref('url');
    builder.metadataWhitelist.push('position');
    
    const documents = {};
    for (let file of await util.promisify(fs.readdir)('./doc')) {
        if (!file.endsWith('.md'))
            continue;

        const md = new markdown();
        md.use(require('markdown-it-anchor'));
        md.use(require('markdown-it-highlightjs'));
        md.use(require('markdown-it-container-pandoc'));
        md.use(require('markdown-it-table-of-contents'), { includeLevel: [2,3] });