How to use the lunr 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 studentinsights / studentinsights / app / assets / javascripts / student_profile / ReaderProfile.js View on Github external
function findNotes(grade, notes, words) {
  if (grade !== 'KF') return null;

  const documents = notes.map(note => {
    return {
      id: note.id,
      text: note.text
    };
  });

  const index = lunr(function() {
    this.ref('id');
    this.field('text');
    this.metadataWhitelist = ['position'];
    documents.forEach(doc => this.add(doc));
  });

  // window.index = index;
  const results = _.flatMap(words, word => index.search(word));
  // console.log('results', results);
  // return JSON.stringify(results);


  const matches = _.flatMap(results, result => {
    const note = notes.filter(note => note.id === parseInt(result.ref, 10))[0]; // need a better way :)
    if (!note) {
      // console.log('no note for result:', results);
github yahoo / fluxible / site / services / docs.js View on Github external
const ENV = process.env.NODE_ENV;
const debug = debugLib('DocsService');
const indexDb = getSearchIndexPath();

marked.setOptions({
    highlight: (code) => {
        return highlight.highlightAuto(code).value;
    }
});

// Generate a hash of valid api routes, from the /configs/apis.js file
let cache = {};
let documents = {};

// setup lunr index
const index = lunr(function () {
    debug('Creating lunr index');
    this.ref('id');
    this.field('title', { boost: 10 });
    this.field('description', { boost: 5 });
    this.field('body');
    this.field('permalink');
});

/**
 * Generic function to call GitHub's 'repos' API
 * https://developer.github.com/v3/repos/
 *
 * @function fetchGitHubReposApi
 * @param {Object} params
 * @param {String} [params.repo=yahoo/fluxible] Repository
 * @param {String} params.type Type of data to fetch
github numenta / numenta-web / packages / components / src / Search / index.jsx View on Github external
constructor(props) {
    super(props)

    // init client-side search indexing
    this._documents = {}
    this._index = lunr(function () {
      this.ref('path')
      this.field('title', {boost: 10})
      this.field('text')
      this.pipeline.remove(lunr.stopWordFilter)
    })

    this.state = {query: ''}
  }
github getsentry / sentry-docs / src / _js / lib / Lunr.js View on Github external
buildIndex(documents) {
    return lunr(function() {
      this.ref('id');
      this.field('body');
      this.metadataWhitelist = ['position'];

      documents.forEach(function(doc) {
        this.add(doc);
      }, this);
    });
  }
github solidusio / solidus / guides / source / assets / javascripts / search.js View on Github external
function populateIndex(data) {
  var index = lunr(function(){
    this.field('title', { boost: 10 });
    this.field('content');
    this.field('url');
    this.ref('id');
    var lunr_index = this

    data.forEach(function(item) {
      lunr_index.add(item);
    });
  });

  return index;
}
github rubykit / kit / kit / libs / kit-doc-yard / assets / src / js / search.js View on Github external
function createIndex () {
  return lunr(function () {
    this.ref('ref')
    this.field('title', {boost: 3, extractor: titleExtractor})
    this.field('doc')
    this.metadataWhitelist = ['position']
    this.pipeline.remove(lunr.stopWordFilter)

    searchNodes.forEach(function (doc) {
      this.add(doc)
    }, this)
  })
}
github swennemans / redux-lunr / src / middleware.js View on Github external
function createLunrIndex(options) {
  let index = options.index;

  return lunr(function() {
    Object.keys(index).forEach((key) => {
      if (key === 'ref') {
        this.ref(index[key])
      } else {
        this.field(key, index[key])
      }
    })
  });
}
github primer / blueprints / src / Search.js View on Github external
function Search({subfolder, documents, next}) {
  const idx = lunr(function() {
    this.ref('path') //eslint-disable-line
    this.field('title')//eslint-disable-line
    this.field('content')//eslint-disable-line
    this.field('keywords')//eslint-disable-line
    for (const doc of Object.values(documents)) {
      this.add(doc) //eslint-disable-line
    }
  })

  const [results, setResults] = useState([])

  const onChange = e => {
    if (e.target) {
      setResults(idx.search(`${e.target.value}*`))
    }
  }
github MyEtherWallet / knowledge-base-v3 / app / core / src / raneto.js View on Github external
doSearch(query) {
    const contentDir = patch_content_dir(path.normalize(this.config.content_dir));
    const files = glob.sync(contentDir + '**/*.md');
    const idx   = lunr(function() {
      this.field('title', { boost: 10 });
      this.field('body');
    });

    files.forEach(filePath => {
      try {
        const shortPath = filePath.replace(contentDir, '').trim();
        const file      = fs.readFileSync(filePath);
        const meta      = this.processMeta(file.toString('utf-8'));

        idx.add({
          id    : shortPath,
          title : meta.title ? meta.title : this.slugToTitle(shortPath),
          body  : file.toString('utf-8')
        });
github roperzh / tachyons-cheatsheet / app / js / components / cheatsheet.js View on Github external
.then((rawData) => {
      const data = JSON.parse(rawData);

      const index = lunr(function() {
        this.field('name', { boost: 10 });
        this.field('tags', { boost: 15 });
        this.field('description');
        this.ref('id');
      });

      data.forEach((item, id) => index.add({ ...item, id }));

      this.setState({ data, index });
      this.search('color');
    });
  }