How to use the algoliasearch-helper.SearchParameters function in algoliasearch-helper

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 algolia / react-instantsearch / packages / react-instantsearch-core / src / connectors / __tests__ / connectGeoSearch.js View on Github external
it('expect to return the given searchParameters when boundingBox is omit', () => {
        const searchParameters = new SearchParameters();
        const props = { contextValue, indexContextValue };
        const searchState = {};

        const actual = connector.getSearchParameters(
          searchParameters,
          props,
          searchState
        );

        expect(actual).toEqual(searchParameters);
      });
    });
github algolia / react-instantsearch / packages / react-instantsearch-core / src / components / __tests__ / Index.js View on Github external
it('provides search parameters from instance props', () => {
    const context = createContext();

    const wrapper = shallow(
      
        <div>
      ,
      {
        context,
      }
    );

    const parameters = wrapper
      .instance()
      .getSearchParameters(new SearchParameters());

    expect(parameters.index).toBe('indexName');
  });
</div>
github algolia / react-instantsearch / packages / react-instantsearch-core / src / connectors / __tests__ / connectHierarchicalMenu.js View on Github external
it('correctly applies its state to search parameters', () => {
      const initSP = new SearchParameters();

      const params = connect.getSearchParameters(
        initSP,
        {
          attributes: ['ATTRIBUTE'],
          separator: 'SEPARATOR',
          rootPath: 'ROOT_PATH',
          showParentLevel: true,
          limit: 1,
          contextValue,
          indexContextValue,
        },
        {
          indices: {
            second: { otherKey: 'val', hierarchicalMenu: { ATTRIBUTE: 'ok' } },
          },
github algolia / react-instantsearch / packages / react-instantsearch-core / src / connectors / __tests__ / connectPagination.js View on Github external
it('refines the page parameter', () => {
      const initSP = new SearchParameters();
      params = connect.getSearchParameters(
        initSP,
        { contextValue, indexContextValue },
        { indices: { second: { page: 667 } } }
      );
      expect(params.page).toBe(666);
    });
github algolia / react-instantsearch / packages / react-instantsearch-core / src / connectors / __tests__ / connectToggleRefinement.js View on Github external
it('refines the corresponding facet with `true`', () => {
      const params = connect.getSearchParameters(
        new SearchParameters(),
        {
          attribute: 'facet',
          value: 'val',
          contextValue,
          indexContextValue,
        },
        {
          indices: {
            second: {
              toggle: {
                facet: true,
              },
            },
          },
        }
      );
github algolia / react-instantsearch / packages / react-instantsearch-core / src / core / createInstantSearchManager.js View on Github external
(acc, result) => ({
          ...acc,
          [result._internalIndexId]: new algoliasearchHelper.SearchResults(
            new algoliasearchHelper.SearchParameters(result.state),
            result.rawResults
          ),
        }),
        {}
github algolia / react-instantsearch / packages / react-instantsearch-core / src / connectors / connectHierarchicalMenu.js View on Github external
function getValue(path, props, searchState, context) {
  const { id, attributes, separator, rootPath, showParentLevel } = props;

  const currentRefinement = getCurrentRefinement(props, searchState, context);
  let nextRefinement;

  if (currentRefinement === null) {
    nextRefinement = path;
  } else {
    const tmpSearchParameters = new algoliasearchHelper.SearchParameters({
      hierarchicalFacets: [
        {
          name: id,
          attributes,
          separator,
          rootPath,
          showParentLevel,
        },
      ],
    });

    nextRefinement = tmpSearchParameters
      .toggleHierarchicalFacetRefinement(id, currentRefinement)
      .toggleHierarchicalFacetRefinement(id, path)
      .getHierarchicalRefinement(id)[0];
  }
github algolia / react-instantsearch / packages / react-instantsearch-dom / src / core / createInstantSearchServer.js View on Github external
const getSearchParameters = (indexName, searchParameters) => {
  const sharedParameters = searchParameters
    .filter(searchParameter => !hasMultipleIndices(searchParameter.context))
    .reduce(
      (acc, searchParameter) =>
        searchParameter.getSearchParameters(
          acc,
          searchParameter.props,
          searchParameter.searchState
        ),
      new algoliasearchHelper.SearchParameters({
        ...HIGHLIGHT_TAGS,
        index: indexName,
      })
    );

  const derivedParameters = searchParameters
    .filter(searchParameter => hasMultipleIndices(searchParameter.context))
    .reduce((acc, searchParameter) => {
      const indexId = getIndexId(searchParameter.context);

      return {
        ...acc,
        [indexId]: searchParameter.getSearchParameters(
          acc[indexId] || sharedParameters,
          searchParameter.props,
          searchParameter.searchState