How to use algoliasearch-helper - 10 common examples

To help you get started, we’ve selected a few algoliasearch-helper 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 DefinitelyTyped / DefinitelyTyped / types / algoliasearch-helper / algoliasearch-helper-tests.ts View on Github external
});
});

// https://community.algolia.com/algoliasearch-helper-js/reference.html#SearchParameters#addTagRefinement

const searchparameter = new SearchParameters();

// for price = 50 or 40
searchparameter.addNumericRefinement('price', '=', [50, 40]);

// for size = 38 and 40
searchparameter.addNumericRefinement('size', '=', 38);
searchparameter.addNumericRefinement('size', '=', 40);

let queryParameters = new SearchParameters({}); // everything is optional
queryParameters = new SearchParameters({
    advancedSyntax: true,
    allowTyposOnNumericTokens: true,
    analytics: true,
    analyticsTags: ['test'],
    aroundLatLng: 'latitude',
    aroundLatLngViaIP: true,
    aroundPrecision: 1,
    aroundRadius: 1,
    attributesToHighlight: ['test'],
    attributesToRetrieve: ['test'],
    attributesToSnippet: ['test'],
    disableExactOnAttributes: ['test'],
    disjunctiveFacets: ['test'],
    disjunctiveFacetsRefinements: { test: ['test'] },
    distinct: 2,
    enableExactOnSingleWordQuery: true,
github DefinitelyTyped / DefinitelyTyped / types / algoliasearch-helper / algoliasearch-helper-tests.ts View on Github external
queryParameters.setFacets(['test']);
queryParameters.setHitsPerPage(1);
queryParameters.setPage(1);
queryParameters.setQuery('test');
queryParameters.setQueryParameter('test', {});
queryParameters.setQueryParameters({ test: {} });
queryParameters.setTypoTolerance('test');
queryParameters.toggleConjunctiveFacetRefinement('test', {});
queryParameters.toggleDisjunctiveFacetRefinement('test', {});
queryParameters.toggleExcludeFacetRefinement('test', {});
queryParameters.toggleFacetRefinement('test', {});
queryParameters.toggleHierarchicalFacetRefinement('test', {});
queryParameters.toggleTagRefinement('test');

// static methods
SearchParameters.make(queryParameters);
SearchParameters.validate(queryParameters, { queryType: 'prefixAll' });
github DefinitelyTyped / DefinitelyTyped / types / algoliasearch-helper / algoliasearch-helper-tests.ts View on Github external
queryParameters.setHitsPerPage(1);
queryParameters.setPage(1);
queryParameters.setQuery('test');
queryParameters.setQueryParameter('test', {});
queryParameters.setQueryParameters({ test: {} });
queryParameters.setTypoTolerance('test');
queryParameters.toggleConjunctiveFacetRefinement('test', {});
queryParameters.toggleDisjunctiveFacetRefinement('test', {});
queryParameters.toggleExcludeFacetRefinement('test', {});
queryParameters.toggleFacetRefinement('test', {});
queryParameters.toggleHierarchicalFacetRefinement('test', {});
queryParameters.toggleTagRefinement('test');

// static methods
SearchParameters.make(queryParameters);
SearchParameters.validate(queryParameters, { queryType: 'prefixAll' });
github algolia / react-instantsearch / src / lib / url-sync.js View on Github external
getConfiguration(currentConfiguration) {
    // we need to create a REAL helper to then get its state. Because some parameters
    // like hierarchicalFacet.rootPath are then triggering a default refinement that would
    // be not present if it was not going trough the SearchParameters constructor
    this.originalConfig = algoliasearchHelper({}, currentConfiguration.index, currentConfiguration).state;
    return this.searchParametersFromUrl;
  }
github sfeir-open-source / angular-search-experience / src / app / core / algolia / algolia.service.ts View on Github external
configureIndex(indexName: string) {
    this.indices[indexName] = algoliasearchHelper(this.client, indexName, {
      disjunctiveFacets: ['category']
    });

    this.searchState = {} as SearchState;

    // handle algolia events
    ['search', 'result', 'change', 'error'].forEach(eventName => {
      this.searchState[`${eventName}$`] = new Observable(observer => {
        const handler = e => observer.next(e);
        this.indices[indexName].on(eventName, handler);
        return () => this.indices[indexName].removeListener(eventName, handler);
      });
    });
  }
github algolia / vue-instantsearch / src / store.js View on Github external
constructor(helper, { stalledSearchDelay = 200 } = {}) {
    if (!(helper instanceof algoliaHelper.AlgoliaSearchHelper)) {
      throw new TypeError(
        'Store should be constructed with an AlgoliaSearchHelper instance as first parameter.'
      );
    }
    // We require one start() call to execute the first search query.
    // Allows every widget to alter the state at initialization
    // without trigger multiple queries.
    this._stoppedCounter = 1;

    this._highlightPreTag = '<em>';
    this._highlightPostTag = '</em>';

    this._cacheEnabled = true;

    this._stalledSearchDelay = stalledSearchDelay;
github algolia / react-instantsearch / src / lib / url-sync.js View on Github external
createURL(state, {absolute}) {
    const currentQueryString = this.urlUtils.readUrl();
    const filteredState = state.filter(this.trackedParameters);
    const foreignConfig = algoliasearchHelper
      .url
      .getUnrecognizedParametersInQueryString(currentQueryString, {mapping: this.mapping});
    // Add instantsearch version to reconciliate old url with newer versions
    // eslint-disable-next-line camelcase
    foreignConfig.is_v = majorVersionNumber;
    const relative = this
      .urlUtils
      .createURL(algoliasearchHelper.url.getQueryStringFromState(filteredState, {mapping: this.mapping}));

    return absolute ? getFullURL(relative) : relative;
  }
github algolia / react-instantsearch / src / lib / url-sync.js View on Github external
createURL(state, {absolute}) {
    const currentQueryString = this.urlUtils.readUrl();
    const filteredState = state.filter(this.trackedParameters);
    const foreignConfig = algoliasearchHelper
      .url
      .getUnrecognizedParametersInQueryString(currentQueryString, {mapping: this.mapping});
    // Add instantsearch version to reconciliate old url with newer versions
    // eslint-disable-next-line camelcase
    foreignConfig.is_v = majorVersionNumber;
    const relative = this
      .urlUtils
      .createURL(algoliasearchHelper.url.getQueryStringFromState(filteredState, {mapping: this.mapping}));

    return absolute ? getFullURL(relative) : relative;
  }
github algolia / react-instantsearch / src / lib / url-sync.js View on Github external
renderURLFromState(state) {
    const currentQueryString = this.urlUtils.readUrl();
    const foreignConfig = AlgoliaSearchHelper
      .getForeignConfigurationInQueryString(currentQueryString, {mapping: this.mapping});
    // eslint-disable-next-line camelcase
    foreignConfig.is_v = majorVersionNumber;

    const qs = urlHelper.getQueryStringFromState(
      state.filter(this.trackedParameters),
      {
        moreAttributes: foreignConfig,
        mapping: this.mapping,
        safe: true
      }
    );

    if (this.timer() &lt; this.threshold) {
      this.urlUtils.replaceState(qs, {getHistoryState: this.getHistoryState});
    } else {
      this.urlUtils.pushState(qs, {getHistoryState: this.getHistoryState});
    }
  }
github algolia / angular-instantsearch / helpers / setup-jest.ts View on Github external
import "jest-preset-angular";

// stupid workaround for TS
import * as helper from "algoliasearch-helper";
require("algoliasearch-helper").default = helper;

const mock = () => {
  let storage = {};
  return {
    getItem(key) {
      return storage[key] || null;
    },
    setItem(key, value) {
      storage[key] = value;
    },
    removeItem(key) {
      delete storage[key];
    },
    clear() {
      storage = {};
    }