$refs.searchInput.focus(), 200)"
@reset-search-form.window="setTimeout(()=>reset(),300)"
x-data="{
autocompleteResults: [],
globalResults: [],
isDirty: false,
query: '',
loadState: 0,
timer: undefined,
autocompleteIndex: {},
globalIndex: {},
scoutPrefix: 'staging_',
reset() {
this.isDirty = false
this.query = '';
this.autocompleteResults = [];
this.globalResults = [];
this.loadState = 0;
},
search(index){
let global = (index === 'globalIndex');
let attrs = {
facetFilters: (global) ? ['is_showable:true'] : '',
attributesToRetrieve: (global) ? ['title', 'published_at', 'intro', 'url', 'type','duration'] : ['title', 'thumbnail_img', 'url'] ,
hitsPerPage: (global) ? 4 : 3
}
this[index].search( this.query , attrs).then((data) => {
if(global){
this.globalResults = data.hits
}else{
this.autocompleteResults = 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 ==='') return;
this.isDirty = true;
this.loadState = 2;
this.search( 'autocompleteIndex' );
this.search( 'globalIndex' );
}
}"
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.