${icons.noResult}
No results have been found for ${query}.
Please rephrase your query!
`;
}
// Detect macOS
function isMac() {
return navigator.platform.toUpperCase().indexOf("MAC") >= 0;
}
// Algolia credintials
const algoliaClient = algoliasearch(
"E1CSOK3UC2",
"6bc246d81fd3b79f51cf88f0b2481bac"
);
// By default, Instantsearch will display the latest hits even without a query.
// As per our design, we don't need this behaviour.
// So, use promise to conditionally render the search results.
const searchClient = {
...algoliaClient,
search(requests) {
if (requests.every(({ params }) => !params.query)) {
return Promise.resolve({
results: requests.map(() => ({
hits: [],
nbHits: 0,
nbPages: 0,
page: 0,
processingTimeMS: 0,
hitsPerPage: 0,
exhaustiveNbHits: false,
query: "",
params: "",
})),
});
}
return algoliaClient.search(requests);
},
};
// Init Instantsearch
const search = instantsearch({
indexName: "minio",
searchClient,
initialUiState: {
minio: {
refinementList: {
platform: [activePlatform],
},
},
},
});
// Add Instanstsearch widgets
search.addWidgets([
instantsearch.widgets.searchBox({
container: "#search-box",
autofocus: true,
showReset: false,
showSubmit: false,
placeholder: "Search Documentation",
cssClasses: {
input: "search__input",
reset: "search__reset",
form: "search__form",
loadingIndicator: "search__loading",
},
queryHook(query, search) {
if (query !== "") {
// Make search modal active
searchModalEl.classList.add("search--focused");
// Clear the filters and select the active platform
setTimeout(() => {
const activeFilterEl = document.querySelector(
".search__filters__checkbox[value='" + activePlatform + "']"
);
if (activeFilterEl && !activeFilterEl.checked) {
activeFilterEl.click();
}
}, 50);
} else {
// Clear the filters
clearRefinements();
}
// Clear the filters on x click
document
.querySelector(".search__reset")
.addEventListener("click", () => {
clearRefinements("btn");
});
// Fire the search
search(query);
},
}),
instantsearch.widgets.poweredBy({
container: "#search-powered-by",
cssClasses: {
link: "search__powered-by",
},
}),
instantsearch.widgets.refinementList({
container: "#search-filters",
attribute: "platform",
cssClasses: {
root: "search__filters",
noRefinementRoot: "search__filters--empty",
list: "search__filters__list",
labelText: "search__filters__label",
checkbox: "search__filters__checkbox",
count: "search__filters__count",
},
}),
instantsearch.widgets.clearRefinements({
container: "#search-clear",
cssClasses: {
button: "search-clear__btn",
},
}),
instantsearch.widgets.hits({
container: "#search-results",
cssClasses: {
root: "search__hits",
emptyRoot: "search__hits--empty",
list: "search__hits__list",
item: "search__hits__item",
},
templates: {
empty: function (data) {
return data.query !== "" ? noResultTemplate(data.query) : "";
},
item: function (data) {
var returnString;
var docUrl;
var refinedLenth =
search.renderState.minio.refinementList.platform.items.filter(
(x) => x.isRefined
).length;
if (refinedLenth !== 1) {
searchModalEl.classList.add("search--show-platform");
} else {
searchModalEl.classList.remove("search--show-platform");
}
// If the query is a full-match of a lvl1 title,
// display only the h1.
if (
data.hierarchy.lvl1 &&
data._highlightResult.hierarchy.lvl1.matchLevel === "full"
) {
docUrl = data.url_without_anchor;
returnString = `
${icons.h1}
${data._highlightResult.hierarchy.lvl1.value}
${data.platform}
`;
}
// If the query is a full-match of a lvl2 title,
// display h2 as the title and h1 as the sub-text.
else if (
data.hierarchy.lvl2 &&
data._highlightResult.hierarchy.lvl2.matchLevel === "full"
) {
docUrl = data.url;
returnString = `
${icons.h2}
${data._highlightResult.hierarchy.lvl2.value}
${data.platform}
${data.hierarchy.lvl1}
`;
}
// If the query is a full-match of a lvl3 title,
// display h3 as the title and h1, h2 as the sub-text.
else if (
data.hierarchy.lvl3 &&
data._highlightResult.hierarchy.lvl3.matchLevel === "full"
) {
docUrl = data.url;
returnString = `
${icons.h3}
${data._highlightResult.hierarchy.lvl3.value}
${data.platform}
${data.hierarchy.lvl1}
`;
}
// If the query is a full-match of any content,
// display the content as the title and h1, h2? and h3? as the sub-text.
else if (
data.hierarchy.lvl1 &&
data._snippetResult &&
data._snippetResult.content.matchLevel !== "none"
) {
docUrl = data.url;
returnString = `
${icons.content}