Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
});
// 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,
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);
});
});
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>
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' } },
},
it('refines the page parameter', () => {
const initSP = new SearchParameters();
params = connect.getSearchParameters(
initSP,
{ contextValue, indexContextValue },
{ indices: { second: { page: 667 } } }
);
expect(params.page).toBe(666);
});
it('refines the corresponding facet with `true`', () => {
const params = connect.getSearchParameters(
new SearchParameters(),
{
attribute: 'facet',
value: 'val',
contextValue,
indexContextValue,
},
{
indices: {
second: {
toggle: {
facet: true,
},
},
},
}
);
(acc, result) => ({
...acc,
[result._internalIndexId]: new algoliasearchHelper.SearchResults(
new algoliasearchHelper.SearchParameters(result.state),
result.rawResults
),
}),
{}
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];
}
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