How to use the lunr.trimmer 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 Googer / Professor-Pine / app / gym.js View on Github external
this.field('natural_feature');
      this.field('postal_code');
      this.field('bus_station');
      this.field('establishment');
      this.field('point_of_interest');
      this.field('transit_station');

      // field for places
      this.field('places');

      // field from supplementary metadata
      this.field('additionalTerms');

      // replace default stop word filter with custom one
      this.pipeline.remove(lunr.stopWordFilter);
      this.pipeline.after(lunr.trimmer, blacklistWordFilter);
      this.pipeline.after(blacklistWordFilter, stopwordFilter);

      mergedGyms.forEach(gym => {
        // Gym document is a object with its reference and fields to collection of values
        const gymDocument = Object.create(null);

        gym.gymName = he.decode(gym.gymName);
        gym.gymInfo.gymDescription = he.decode(gym.gymInfo.gymDescription);

        // static fields
        gymDocument['name'] = removeDiacritics(gym.gymName).replace(/[^\w\s-]+/g, '');
        gymDocument['description'] = removeDiacritics(gym.gymInfo.gymDescription).replace(/[^\w\s-]+/g, '');

        if (gym.nickname) {
          gym.nickname = he.decode(gym.nickname);
          gymDocument['nickname'] = removeDiacritics(gym.nickname).replace(/[^\w\s-]+/g, '');
github Googer / Professor-Pine / app / gym.js View on Github external
this.field('colloquial_area');
      this.field('locality');
      this.field('premise');
      this.field('natural_feature');
      this.field('postal_code');
      this.field('bus_station');
      this.field('establishment');
      this.field('point_of_interest');
      this.field('transit_station');

      // field for places
      this.field('places');

      // replace default stop word filter with custom one
      this.pipeline.remove(lunr.stopWordFilter);
      this.pipeline.after(lunr.trimmer, Gym.blacklistWordFilter);
      this.pipeline.after(Gym.blacklistWordFilter, Search.stopWordFilter);

      gyms.forEach(gym => {
        // Gym document is a object with its reference and fields to collection of values
        const gymDocument = Object.create(null);

        gymDocument["id"] = gym.id;

        gym.name = he.decode(gym.name);
        if (gym.description) {
          gym.description = he.decode(gym.description);
        } else {
          gym.description = "";
        }

        // static fields
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)
    .then(fileNames =>
github lbryio / lbry.tech / content / .vuepress / components / Slate.vue View on Github external
this.$nextTick(function () {
          this.makeToc();

          this.searchIndex = new lunr.Index();

          this.searchIndex.ref("id");
          this.searchIndex.field("title", { boost: 10 });
          this.searchIndex.field("body");
          this.searchIndex.pipeline.add(lunr.trimmer, lunr.stopWordFilter);

          this.populateSearchIndex();
          this.bindSearchIndex();
        });
      }).catch(error => {
github Redocly / redoc / src / services / SearchWorker.worker.ts View on Github external
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());
}

export async function toJS() {
  return {
    store,