const search = instantsearch({
appId: 'ITI5JHZJM9',
apiKey: 'b427318cf6d881e5d3ffd84adf39219e',
indexName: 'diybiosphere',
urlSync: true,
searchParameters: {
facetingAfterDistinct: true
}
});
search.addWidget(
instantsearch.widgets.searchBox({
container: '#search-box',
reset: false,
poweredBy: false,
magnifier: false,
placeholder: 'Search for (almost) anything in the entries, like `protocol`',
cssClasses: {
root: 'ui input'
}
})
);
search.addWidget(
instantsearch.widgets.stats({
container: '#stats-container',
cssClasses: {
body: 'ui medium header',
},
templates: {
body: 'Browse {{nbHits}} entries found {{#query}}matching:"{{query}}"{{/query}}'
}
})
);
search.addWidget(
instantsearch.widgets.clearAll({
container: '#clear-all',
autoHideContainer: true,
templates: {
link: ' Erase all '
},
})
);
search.addWidget(
instantsearch.widgets.currentRefinedValues({
container: '#current-refined-values',
autoHideContainer: true,
clearAll: false,
cssClasses: {
root: 'ui horizontal list',
header: 'item ui small header',
body: 'item',
list: 'ui horizontal list',
item: 'item',
},
templates: {
item: '{{name}} ',
},
})
);
const EMPTY_TEMPLATE =
'
No results found matching {{query}} .
';
/* Add below to template if new collection
{{#NEW_COLLECTION}} NEW_COLLECTION {{/NEW_COLLECTION}}
*/
const HIT_TEMPLATE = `
{{{ _highlightResult.content.value }}}
`;
/* Add below to template if new collection
{{#NEW_COLLECTION}}NEW_COLLECTION{{/NEW_COLLECTION}}
*/
const TABLE_TEMPLATE = `
Title
Collection
Type
Start
End
City
Country
Last Edit
{{#hits}}
{{{ _highlightResult.title.value }}}
{{#project}}Project{{/project}}{{#startup}}Startup{{/startup}}{{#lab}}Lab{{/lab}}{{#incubator}}Incubator{{/incubator}}{{#group}}Group{{/group}}{{#network}}Network{{/network}}{{#event}}Event{{/event}}{{#other}}Other{{/other}}
{{type-org}}
{{start-date}}
{{end-date}}
{{{ _highlightResult.city.value }}}
{{{ _highlightResult.country.value }}}
{{last_modified_at}}
{{/hits}}
`;
const gridHits = instantsearch.widgets.hits({
container: '#hits-container',
templates: {
empty: EMPTY_TEMPLATE,
item: HIT_TEMPLATE
},
});
const tableHits = instantsearch.widgets.hits({
container: '#table-container',
templates: {
empty: EMPTY_TEMPLATE,
allItems: TABLE_TEMPLATE
},
});
search.addWidget(
instantsearch.widgets.refinementList({
container: '#status',
attributeName: 'status',
operator: 'or',
limit: 10,
cssClasses: {
list: 'ui small horizontal link list xo paddingless',
item: 'item',
active: 'active item',
},
templates: {
item: '[{{value}} {{count}}] ',
}
})
);
search.addWidget(
instantsearch.widgets.refinementList({
container: '#collection',
attributeName: 'collection',
operator: 'or',
limit: 10,
cssClasses: {
list: 'ui small horizontal link list xo paddingless',
item: 'item',
active: 'active item',
},
templates: {
item: '[{{value}} {{count}}] ',
}
})
);
search.addWidget(
instantsearch.widgets.refinementList({
container: '#type-org',
attributeName: 'type-org',
operator: 'or',
limit: 10,
cssClasses: {
list: 'ui small horizontal link list',
item: 'item',
active: 'active item',
},
templates: {
item: '[{{value}} {{count}}] ',
}
})
);
search.addWidget(
instantsearch.widgets.refinementList({
container: '#country',
attributeName: 'country',
operator: 'or',
limit: 10,
showMore: true,
cssClasses: {
list: 'ui small horizontal link list',
item: 'item',
active: 'active item',
},
templates: {
item: '[{{value}} {{count}}] ',
}
})
);
search.addWidget(
instantsearch.widgets.refinementList({
container: '#tags',
attributeName: 'tags',
operator: 'or',
limit: 10,
showMore: true,
cssClasses: {
list: 'ui small horizontal link list',
item: 'item',
active: 'active item',
},
templates: {
item: '[{{value}} {{count}}] ',
}
})
);
search.addWidget(
instantsearch.widgets.hitsPerPageSelector({
container: '#hits-per-page-selector',
autoHideContainer: true,
cssClasses: {
root: 'select',
},
items: [
{value: 10, label: '10 per page', default: true},
{value: 100, label: '100 per page'},
{value: 1000, label: '1000 per page'},
],
})
);
search.addWidget(
instantsearch.widgets.pagination({
container: '#pagination-container',
maxPages: 100,
padding: 1,
scrollTo: false,
showFirstLast: true,
autoHideContainer: true,
cssClasses: {
root: 'ui small compact menu',
item: 'item',
disabled: 'disabled item',
active: 'active item',
}
})
);
search.addWidget(
instantsearch.widgets.pagination({
container: '#bottom-pagination-container',
maxPages: 100,
padding: 1,
scrollTo: false,
showFirstLast: true,
autoHideContainer: true,
cssClasses: {
root: 'ui small compact menu',
item: 'item',
disabled: 'disabled item',
active: 'active item',
}
})
);
search.addWidget(
instantsearch.widgets.sortBySelector({
container: '#sort-by-container',
cssClasses: {
root: 'select',
},
indices: [
{name: 'diybiosphere', label: 'Title(a-z)'},
{name: 'title(desc)', label: 'Title(z-a)'},
{name: 'country(asc)', label: 'Country(a-z)'},
{name: 'country(desc)', label: 'Country(z-a)'},
{name: 'start-date(asc)', label: 'Start date(asc)'},
{name: 'start-date(desc)', label: 'Start date(desc)'},
{name: 'end-date(asc)', label: 'End date(asc)'},
{name: 'end-date(desc)', label: 'End date(desc)'},
{name: 'last-edit(desc)', label: 'Newest edit'},
{name: 'last-edit(asc)', label: 'Oldest edit'}
]
})
);
search.addWidget(gridHits);
search.addWidget(tableHits);
search.start();