How to use the lunr.Query 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 / search.js View on Github external
static singleTermSearch(term, index, fields) {
    if (!fields) {
      fields = index.fields;
    }

    if (term.length > 15) {
      term = term.substring(0, 14) + lunr.Query.wildcard;
    }

    return index.query(query => {
      query.term(term,
        {
          fields: fields,
          usePipeline: true,
          boost: 100
        });

      if (term.includes(lunr.Query.wildcard)) {
        // wildcard in term, disable stemming
        query.term(term,
          {
            fields: fields,
            usePipeline: false,
github rlingineni / Lambda-Serverless-Search / document_search / app.js View on Github external
let results = index.query(function() {
		// exact matches should have the highest boost
		this.term(lunr.tokenizer(query), { boost: 100 });

		// prefix matches should be boosted slightly
		this.term(query, { boost: 10, usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING });

		// finally, try a fuzzy search with character 2, without any boost
		this.term(query, { boost: 5, usePipeline: false, editDistance: 2 });
	});
	return results.slice(0, numValues);
github bitwarden / jslib / src / services / search.service.ts View on Github external
// Fall back to basic search if index is not available
            return this.searchCiphersBasic(ciphers, query);
        }

        const ciphersMap = new Map();
        ciphers.forEach((c) => ciphersMap.set(c.id, c));

        let searchResults: lunr.Index.Result[] = null;
        const isQueryString = query != null && query.length > 1 && query.indexOf('>') === 0;
        if (isQueryString) {
            try {
                searchResults = index.search(query.substr(1).trim());
            } catch { }
        } else {
            // tslint:disable-next-line
            const soWild = lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING;
            searchResults = index.query((q) => {
                lunr.tokenizer(query).forEach((token) => {
                    const t = token.toString();
                    q.term(t, { fields: ['name'], wildcard: soWild });
                    q.term(t, { fields: ['subtitle'], wildcard: soWild });
                    q.term(t, { fields: ['login.uris'], wildcard: soWild });
                    q.term(t, {});
                });
            });
        }

        if (searchResults != null) {
            searchResults.forEach((r) => {
                if (ciphersMap.has(r.ref)) {
                    results.push(ciphersMap.get(r.ref));
                }
github veteransaffairscanada / vac-benefits-directory / components / search.js View on Github external
value.split(" ").forEach(term => {
          q.term(term, { usePipeline: true, boost: 100 });
          q.term(term, {
            usePipeline: false,
            boost: 10,
            wildcard: lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING
          });
          q.term(term, { usePipeline: false, editDistance: 1 });
        });
      });
github veteransaffairscanada / vac-benefits-directory / selectors / benefits.js View on Github external
searchString.split(/\s+/).forEach(term => {
        q.term(term, { usePipeline: true, boost: 100 });
        q.term(term, {
          usePipeline: false,
          boost: 10,
          wildcard: lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING
        });
        q.term(term, { usePipeline: false, editDistance: 1 });
      });
    });
github Soluto / tweek / services / authoring / src / routes / search.ts View on Github external
function addTerm(query, term, field) {
  query.term(term, { field });
  query.term(term, {
    field,
    wildcard: lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING,
  });
  query.term(term, {
    field,
    wildcard: lunr.Query.wildcard.LEADING,
    editDistance: 1,
  });
}
github Soluto / tweek / services / editor / server / common / perform-search.js View on Github external
function addTerm(query, term, field) {
  query.term(term, { field });
  query.term(term, {
    field,
    wildcard: lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING,
  });
  query.term(term, {
    field,
    wildcard: lunr.Query.wildcard.LEADING,
    editDistance: 1,
  });
}
github Soluto / tweek / services / authoring / src / routes / search.ts View on Github external
function addTerm(query, term, field) {
  query.term(term, { field });
  query.term(term, {
    field,
    wildcard: lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING,
  });
  query.term(term, {
    field,
    wildcard: lunr.Query.wildcard.LEADING,
    editDistance: 1,
  });
}