Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "pelias-query in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'pelias-query' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

query.score( peliasQuery.view.address('housenumber') );
query.score( peliasQuery.view.address('street') );
query.score( peliasQuery.view.address('cross_street') );
query.score( peliasQuery.view.address('postcode') );

// scoring boost
query.score( peliasQuery.view.focus( views.ngrams_strict ) );
query.score( peliasQuery.view.popularity( peliasQuery.view.leaf.match_all ) );
query.score( peliasQuery.view.population( peliasQuery.view.leaf.match_all ) );
query.score( views.custom_boosts( config.get('api.customBoosts') ) );

// non-scoring hard filters
query.filter( views.max_character_count_layer_filter(['address'], config.get('api.autocomplete.exclude_address_length' ) ) );
query.filter( peliasQuery.view.sources );
query.filter( peliasQuery.view.layers );
query.filter( peliasQuery.view.boundary_rect );
query.filter( peliasQuery.view.boundary_circle );
query.filter( peliasQuery.view.boundary_country );
query.filter( peliasQuery.view.categories );
query.filter( peliasQuery.view.boundary_gid );
query.filter( views.focus_point_filter );

// --------------------------------

/**
  map request variables to query variables for all inputs
  provided by this HTTP request.
**/
function generateQuery( clean ){

  const vs = new peliasQuery.Vars( defaults );
// get a copy of the *complete* tokens produced from the input:name
  const tokens = vs.var('input:name:tokens_complete').get();

  // no valid tokens to use, fail now, don't render this view.
  if( !tokens || tokens.length < 1 ){ return null; }

  // set the 'input' variable to all but the last token
  vs.var(`match_phrase:${view_name}:input`).set( tokens.join(' ') );
  vs.var(`match_phrase:${view_name}:field`).set(vs.var('phrase:field').get());

  vs.var(`match_phrase:${view_name}:analyzer`).set(vs.var('phrase:analyzer').get());
  vs.var(`match_phrase:${view_name}:boost`).set(vs.var('phrase:boost').get());
  vs.var(`match_phrase:${view_name}:slop`).set(vs.var('phrase:slop').get());

  return peliasQuery.view.leaf.match_phrase(view_name)( vs );
};
const peliasQuery = require('pelias-query');
const defaults = require('./search_defaults');
const logger = require('pelias-logger').get('api');
const _ = require('lodash');
const check = require('check-types');

//------------------------------
// general-purpose search query
//------------------------------
const venuesQuery = new peliasQuery.layout.VenuesQuery();

// scoring boost
venuesQuery.score( peliasQuery.view.focus_only_function( peliasQuery.view.phrase ) );
// --------------------------------

// non-scoring hard filters
venuesQuery.filter( peliasQuery.view.boundary_country );
venuesQuery.filter( peliasQuery.view.boundary_circle );
venuesQuery.filter( peliasQuery.view.boundary_rect );
venuesQuery.filter( peliasQuery.view.sources );
// --------------------------------

const adminLayers = ['neighbourhood', 'borough', 'city', 'county', 'state', 'country'];

/**
  map request variables to query variables for all inputs
  provided by this HTTP request.  This function operates on res.data which is the
  Document-ified placeholder repsonse.
**/
var placeTypes = require('../helper/placeTypes');
var views = { custom_boosts: require('./view/boost_sources_and_layers') };

// region_a is also an admin field which can be identified by
// the pelias_parser. this functionality was inherited from the
// previous parser we used prior to the creation of pelias_parser.
var adminFields = placeTypes.concat(['region_a']);

//------------------------------
// general-purpose search query
//------------------------------
var query = new peliasQuery.layout.FilteredBooleanQuery();

// mandatory matches
query.score( peliasQuery.view.ngrams, 'must' );

// scoring boost
const phrase_view = peliasQuery.view.leaf.match_phrase('main');

query.score( phrase_view );
query.score( peliasQuery.view.focus( phrase_view ) );
query.score( peliasQuery.view.popularity( peliasQuery.view.leaf.match_all ) );
query.score( peliasQuery.view.population( peliasQuery.view.leaf.match_all ) );

// address components
query.score( peliasQuery.view.address('housenumber') );
query.score( peliasQuery.view.address('street') );
query.score( peliasQuery.view.address('cross_street') );
query.score( peliasQuery.view.address('postcode') );

// admin components
module.exports = function( vs ){

  // validate required params
  if( !vs.isset('phrase:slop') ){
    return null;
  }

  vs.var('match_phrase:ngrams_strict:input', vs.var('input:name').get());
  vs.var('match_phrase:ngrams_strict:field', vs.var('ngram:field').get());

  vs.var('match_phrase:ngrams_strict:analyzer', vs.var('ngram:analyzer').get());
  vs.var('match_phrase:ngrams_strict:slop', vs.var('phrase:slop').get());
  vs.var('match_phrase:ngrams_strict:boost', vs.var('ngram:boost').get());

  return peliasQuery.view.leaf.match_phrase('ngrams_strict')(vs);
};
const peliasQuery = require('pelias-query');
const defaults = require('./search_defaults');

//------------------------------
// general-purpose search query
//------------------------------
const addressUsingIdsQuery = new peliasQuery.layout.AddressesUsingIdsQuery();

// scoring boost
addressUsingIdsQuery.score( peliasQuery.view.focus_only_function( ) );
// --------------------------------

// non-scoring hard filters
addressUsingIdsQuery.filter( peliasQuery.view.boundary_country );
addressUsingIdsQuery.filter( peliasQuery.view.boundary_circle );
addressUsingIdsQuery.filter( peliasQuery.view.boundary_rect );
addressUsingIdsQuery.filter( peliasQuery.view.sources );
addressUsingIdsQuery.filter( peliasQuery.view.boundary_gid );
// --------------------------------

// This query is a departure from traditional Pelias queries where textual
// names of admin areas were looked up.  This query uses the ids returned by
// placeholder for lookups which dramatically reduces the amount of information
// that ES has to store and allows us to have placeholder handle altnames on
// behalf of Pelias.
//
// For the happy path, an input like '30 West 26th Street, Manhattan' would result
// in:
// neighbourhood_id in []
// borough_id in [421205771]
// locality_id in [85945171, 85940551, 85972655]
// localadmin_id in [404502889, 404499147, 404502891, 85972655]
//------------------------------
var query = new peliasQuery.layout.FilteredBooleanQuery();

// mandatory matches
query.score( peliasQuery.view.ngrams, 'must' );

// scoring boost
const phrase_view = peliasQuery.view.leaf.match_phrase('main');

query.score( phrase_view );
query.score( peliasQuery.view.focus( phrase_view ) );
query.score( peliasQuery.view.popularity( peliasQuery.view.leaf.match_all ) );
query.score( peliasQuery.view.population( peliasQuery.view.leaf.match_all ) );

// address components
query.score( peliasQuery.view.address('housenumber') );
query.score( peliasQuery.view.address('street') );
query.score( peliasQuery.view.address('cross_street') );
query.score( peliasQuery.view.address('postcode') );

// admin components
query.score( peliasQuery.view.admin_multi_match(adminFields, 'peliasAdmin') );
query.score( views.custom_boosts( config.customBoosts ) );

// non-scoring hard filters
query.filter( peliasQuery.view.boundary_circle );
query.filter( peliasQuery.view.boundary_rect );
query.filter( peliasQuery.view.sources );
query.filter( peliasQuery.view.layers );
query.filter( peliasQuery.view.categories );
query.filter( peliasQuery.view.boundary_country );
query.filter( peliasQuery.view.boundary_gid );
module.exports = function( vs ){

  // clone the $vs so we can modify this copy without
  // mutating the 'actual' query variables which get shared
  // with the other views.
  var vsClone = new peliasQuery.Vars( vs.export() );

  // set 'input:name' to the result of removeHouseNumber($name);
  if( vsClone.isset('input:name') ){
    var nameVar = vsClone.var('input:name');
    nameVar.set( removeHouseNumber( nameVar.get() ) );
  }

  // run the original ngram view but with the modified input:name' var
  return peliasQuery.view.ngrams( vsClone );
};
const _ = require('lodash');
const peliasQuery = require('pelias-query');
const defaults = require('./search_defaults');
const textParser = require('./text_parser');

//------------------------------
// general-purpose search query
//------------------------------
var fallbackQuery = new peliasQuery.layout.FallbackQuery();

// scoring boost
fallbackQuery.score( peliasQuery.view.focus_only_function( ) );
fallbackQuery.score( peliasQuery.view.popularity_only_function );
fallbackQuery.score( peliasQuery.view.population_only_function );
// --------------------------------

// non-scoring hard filters
fallbackQuery.filter( peliasQuery.view.boundary_country );
fallbackQuery.filter( peliasQuery.view.boundary_circle );
fallbackQuery.filter( peliasQuery.view.boundary_rect );
fallbackQuery.filter( peliasQuery.view.sources );
fallbackQuery.filter( peliasQuery.view.layers );
fallbackQuery.filter( peliasQuery.view.categories );
fallbackQuery.filter( peliasQuery.view.boundary_gid );
// --------------------------------

/**
  map request variables to query variables for all inputs
  provided by this HTTP request.
**/
function generateQuery( clean, res ){
  const vs = new peliasQuery.Vars( defaults );
  const results = _.defaultTo(res.data, []);

  // sources
  if( !_.isEmpty(clean.sources) ) {
    vs.var( 'sources', clean.sources);
  }

  // size
  if( clean.querySize ) {
    vs.var( 'size', clean.querySize );
  }

  if( ! _.isEmpty(clean.parsed_text.number) ){
    vs.var( 'input:housenumber', clean.parsed_text.number );
  }

Is your System Free of Underlying Vulnerabilities?
Find Out Now