How to use search-query-parser - 9 common examples

To help you get started, we’ve selected a few search-query-parser 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 wellcometrust / wellcomecollection.org / whats_on / app / controllers.js View on Github external
export async function renderExhibits(ctx, next) {
  const query = searchQuery.parse(ctx.query.query, { keywords: ['ids'] });
  if (!query.ids) return;
  // searchQueryParser automatically changes comma seperated lists into arrays
  const ids = typeof query.ids === 'string' ? query.ids.split(',') : query.ids;
  const exhibits = await getExhibitionExhibits(ctx.request, {ids});

  ctx.render('components/exhibits/exhibits', {
    exhibits: exhibits.results
  });

  ctx.body = {
    html: ctx.body
  };
}
github buildkite / frontend / app / components / job / Index / jobs.js View on Github external
parseSearchQuery(query) {
    const searchQueryParams = searchQuery.parse(query, { keywords: SEARCH_KEYWORDS });
    const variables = { concurrency: { group: null }, states: null, agentQueryRules: null };

    if (typeof searchQueryParams === 'string') {
      variables.agentQueryRules = searchQueryParams;
    } else if (searchQueryParams) {
      variables.agentQueryRules = searchQueryParams.text;
      variables.concurrency.group = searchQueryParams['concurrency-group'];

      // Ensure the states are all upper case since it's a GraphQL enum
      const states = searchQueryParams['state'];
      if (states) {
        if (typeof states === 'string') {
          variables.states = states.toUpperCase();
        } else {
          variables.states = states.map((state) => state.toUpperCase());
        }
github npms-io / queries / lib / util / parseSearchQuery.js View on Github external
function parseSearchQuery(query, options) {
    options = Object.assign({ throwOnInvalid: false }, options);

    // Parse query into object
    query = searchQueryParser.parse(query, { keywords: qualifiers });
    query = typeof query === 'string' ? { text: query } : query;
    query = mapKeys(query, (value, key) => camelCase(key)); // CamelCase keys
    delete query.exclude; // We do not use the exclusion feature from search-query-parser
    delete query.offsets; // Remove `offsets` otherwise validation will fail

    // Convert & validate
    const validation = Joi.validate(query, paramsSchema, { abortEarly: options.throwOnInvalid });
    let params = validation.value;

    if (validation.error) {
        // Throw if there's an error and `options.throwOnInvalid` is enabled
        if (options.throwOnInvalid && validation.error) {
            throw validation.error;
        }

        // If `options.throwOnInvalid` is enabled, remove all failed validation props and fill it with defaults
github wellcometrust / wellcomecollection.org / common / services / prismic / search.js View on Github external
export function parseQuery(query: string): StructuredSearchQuery {
  const structuredQuery = searchQueryParser.parse(query, {
    keywords: [
      'types',
      'type',
      'ids',
      'id',
      'tags',
      'tag',
      'pageSize',
      'orderings',
      // content type specific
      'article-series',
    ],
  });
  const arrayedStructuredQuery = Object.keys(structuredQuery).reduce(
    (acc, key) => {
      const value = structuredQuery[key];
github beepboopbangbang / githoard / src / main / modules / events.js View on Github external
ipcMain.on('db-search', (event, query) => {
      const searchOptions = {
        keywords: ['slug', 'branch', 'name', 'owner', 'source', 'url', 'createdAt', 'updatedAt'],
        ranges: ['createdAt', 'updatedAt']
      };
      let parsedQuery = searchQuery.parse(query, searchOptions);
      if (typeof parsedQuery === 'string') {
        if (parsedQuery !== '') {
          parsedQuery = { slug: parsedQuery };
        } else {
          parsedQuery = {};
        }
      }
      const { offsets, exclude, ...pq } = parsedQuery; // eslint-disable-line
      this.utilsDb
        .get(toMongo(pq))
        .then((docs) => {
          event.sender.send('reset-list', docs);
        });
    });
  }
github npms-io / queries / lib / util / parseSearchQuery.js View on Github external
function discardQualifiers(query) {
    query = searchQueryParser.parse(query, { keywords: qualifiers });

    return (typeof query === 'string' ? query : query.text || '').trim();
}
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / core / components / search / search.ts View on Github external
parse(query: string) {
    const parsedQuery = parse(query, this.config);

    if (typeof parsedQuery === 'string') {
      return {
        text: parsedQuery,
      } as SearchParserResult;
    }

    return parsedQuery;
  }
}
github vuikit / vuikit / src / lib / Filter / index.js View on Github external
parsed () {
      return sQuery.parse(this.query, this.parser)
    }
  },
github npms-io / npms-api / lib / util / parseQuery.js View on Github external
function discardQualifiers(query) {
    query = searchQueryParser.parse(query, { keywords });

    return (typeof query === 'string' ? query : query.text || '').trim();
}

search-query-parser

Parser for advanced search query syntax

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis

Popular search-query-parser functions