Hi thanks for you answer, unfortunately that doesn’t solve the issue in my side. Let me explain my case again. I have an input form with search parameter that creates a URL sort of like this one:
BaseURL/search/?q=ux
Then I have (on a different page) the search results page and the instant search implementation.
I would like the results page to be filtered by whatever is after the query parameter when I search from something in any page.
This is my search setup, note that I am trying to add something that reads from the url and passes it to the search box but unsuccessfully :
// Adding a query paramater.
var url_string = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname + window.location.search; //window.location.href
var url = new URL(url_string);
var q = url.searchParams.get("q");
const searchClient = algoliasearch('XXX', 'XXX');
const search = instantsearch({
searchClient: searchClient,
indexName: 'XXXX_XXXX',
routing: true,
searchParameters: {
query: q,
}
});
search.addWidget(
instantsearch.widgets.searchBox({
container: '#searchbox',
placeholder: 'Búsqueda',
autofocus: false,
searchAsYouType: true,
searchParameters: {
query: q,
}
})
);
search.addWidget(
instantsearch.widgets.hits({
container: '#hits',
templates: {
empty: 'No se han encontrado resultados',
// https://caniuse.com/#feat=template-literals
item: '<div class="my-3"><h3><a href="{{ permalink }}">{{{ _highlightResult.title.value }}}</a></h3><small class="text-muted">{{ summary }}</small></div>'
},
transformData: {
item: function(data) {
data.lastmod_date = new Date(data.lastmod*1000).toISOString().slice(0,10)
// https://caniuse.com/#search=MAP
const tags = data.tags.map(function(value) {
return value.toLowerCase().replace(' ', '-')
})
data.tags_text = tags.join(', ')
return data
}
}
})
);
search.addWidget(
instantsearch.widgets.stats({
container: "#stats",
templates: {
body(hit) {
return `<span role="img" aria-label="emoji">⚡️</span> <strong>${hit.nbHits}</strong> resultados encontrados ${
hit.query != "" ? `for <strong>"${hit.query}"</strong>` : ``
} in <strong>${hit.processingTimeMS}ms</strong>`;
}
}
})
);
search.addWidgets([
instantsearch.widgets.refinementList({
container: document.querySelector('#filtros'),
attribute: 'categorias',
})
]);
search.addWidgets([
instantsearch.widgets.refinementList({
container: document.querySelector('#tagcloud'),
attribute: 'etiquetas',
})
]);
search.addWidget(
instantsearch.widgets.pagination({
container: '#pagination',
maxPages: 20,
// default is to scroll to 'body', here we disable this behavior
scrollTo: false
})
);
search.start();