fields: ['title', 'text', 'keywords'], // fields to index for full-text search
storeFields: ['id', 'title', 'text', 'type', 'url', 'thumb'], // fields to return with search results
searchOptions: {
- prefix: false, // Allow partial matches
- //processTerm: (term, _fieldName) => term.length < 3 ? null : term.toLowerCase()
+ prefix: true, // Allow partial matches
+ processTerm: (term, _fieldName) => term.length < 3 ? null : term.toLowerCase()
},
- }, querystring: '', // The search query
+ },
query: '', // The search query
- results:[],
- resultCount:0,
medialibrary: '', // Holds URL of the media library that is passed in from the component
async init() {
// Delay miniSearch initialisation so there's less chance of animations stuttering during page loads
setTimeout(() => {
this.miniSearch = new MiniSearch(this.setup);
- this.miniSearch.addAll(minisearchodl);
+ this.miniSearch.addAllAsync(minisearchodl);
}, 4000);
this.medialibrary = this.$el.dataset.medialibrary;
return `<a href="${URL}" class="${classes}" ${attributes}>${result.title}</a>`;
},
- doSearch() {
- this.query = this.querystring;
- this.results = [];
- if (this.query.length >= 3) {
- this.results = this.miniSearch.search(this.query);
- if (this.results.length === 1) {
- this.resultCount = '1 résultat'
- } else {
- this.resultCount = this.results.length + ' résultats';
- }
- } else {
- this.resultCount = "Veuillez taper au moins 3 caractères";
+ get results() {
+ if (this.query.length < 3) {
+ return [];
}
+
+ return this.miniSearch.search(this.query);
+ },
+
+ get resultCount() {
+ if (this.query.length < 3) {
+ return "Veuillez taper au moins 3 caractères";
+ }
+ if (this.results.length === 1) {
+ return '1 résultat'
+ }
+
+ return `${this.results.length} résultats`;
},
});