$refs.searchInput.focus(), 200)"
@reset-search-form.window="setTimeout(()=>reset(),300)"
x-data="{
autocompleteResults: [],
globalResults: [],
isDirty: false,
query: '',
loadState: 0,
timer: undefined,
autocompleteIndex: {},
autocompleteItems: [],
globalIndex: {},
scoutPrefix: 'production_',
reset() {
this.isDirty = false
this.query = '';
this.autocompleteResults = [];
this.globalResults = [];
this.loadState = 0;
},
search(index, seriesOnly = false){
let global = (index === 'globalIndex');
if(!seriesOnly){
var attrs = {
facetFilters: (global) ? ['is_showable:true'] : '',
attributesToRetrieve: (global) ? ['title', 'published_at', 'intro', 'url', 'type','duration'] : ['title', 'thumbnail_img', 'url'] ,
hitsPerPage: (global) ? 4 : 2
}
}else{
var attrs = {
facetFilters: ['is_showable:true', ['type:Podcasts', 'type:Audio series']],
attributesToRetrieve: ['title', 'thumbnail_img', 'url'],
hitsPerPage: 2
}
}
this[index].search( this.query , attrs).then((data) => {
if(global && !seriesOnly){
this.globalResults = data.hits
}else{
if(seriesOnly){
if(this.query==='') return;
this.autocompleteItems = [ ...data.hits, ...this.autocompleteItems].filter((item, index, self) =>
index === self.findIndex((t) => t.title === item.title)
);
this.autocompleteResults = this.autocompleteItems;
}else{
this.autocompleteItems = data.hits
}
}
}).catch((e) => console.log(e) )
},
initiateAlgoliaClient(index, position){
var algolia_app_id = '5XMM0C4W8F';
var algolia_search_key = 'a826cf646db00d89417349288552ac93';
const searchClient = algoliasearch(algolia_app_id,algolia_search_key);
this[position] = searchClient.initIndex(index);
},
init() {
this.initiateAlgoliaClient( `${this.scoutPrefix}general_content_search`, 'globalIndex' );
this.initiateAlgoliaClient( `${this.scoutPrefix}autocomplete_index`, 'autocompleteIndex' );
},
trigger( value ){
if(value ===''){
this.globalResults = [];
this.autocompleteResults = [];
return;
}
this.isDirty = true;
this.loadState = 2;
this.search( 'autocompleteIndex' );
this.search( 'globalIndex' );
// Wait for autoComplete index to make roundtrip
setTimeout(() => this.search( 'globalIndex', true), 100)
}
}"
class="bg-grey-900 text-white rounded-sm sm:mt-10 mb-20 h-full sm:h-auto"
>
Enter a search term to search for presenters, podcasts, music and more.