From 41eb5e256fbcee33e1e554e88228a759aa59a056 Mon Sep 17 00:00:00 2001 From: Stephan Preeker Date: Fri, 10 Nov 2017 19:09:14 +0100 Subject: [PATCH] T53161 WIP javascript search WIP WIP --- src/scripts/tutti/4_search.js | 36 +++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/scripts/tutti/4_search.js b/src/scripts/tutti/4_search.js index c705fa1a..9c53603c 100644 --- a/src/scripts/tutti/4_search.js +++ b/src/scripts/tutti/4_search.js @@ -7,16 +7,44 @@ $(document).ready(function() { if (typeof algoliaIndex === 'undefined') return; + var elasticSearch = function() { + + console.log('yay'); + + return function findMatches(q, cb, async){ + let newhits = []; + // do a query + console.log(q); + $.getJSON("/api/newsearch?q=" + q, function( data ) { + console.log(data.hits.hits); + let hits = data.hits.hits; + newhits = hits.map(function(hit){ + console.log(hit._source); + return hit._source; + }); + console.log(newhits); + cb(newhits); + console.log(cb); + async(); + }); + //api/newsearch?q=test%20dji + // return the matches.. + //cb(matches); + }; + + }; var searchInput = $('#cloud-search'); var tu = searchInput.typeahead({hint: true}, { - source: algoliaIndex.ttAdapter(), + //source: algoliaIndex.ttAdapter(), + source: elasticSearch(), displayKey: 'name', limit: 10, minLength: 0, templates: { suggestion: function(hit) { - + console.log('hit2'); + console.log(hit); var hitMedia = (hit.media ? ' ยท '+hit.media+'' : ''); var hitFree = (hit.is_free ? '
free
' : ''); var hitPicture; @@ -76,6 +104,7 @@ $(document).ready(function() { }); searchInput.keyup(function(e) { + console.log('upupup'); if ( $('.tt-dataset').is(':empty') ){ if(e.keyCode == 13){ window.location.href = '/search#q='+ $("#cloud-search").val() + '&page=1'; @@ -84,6 +113,9 @@ $(document).ready(function() { }); searchInput.bind('typeahead:render', function(event, suggestions, async, dataset) { + console.log('woot'); + console.log(suggestions); + console.log(dataset); if( suggestions != undefined && $('.tt-all-results').length <= 0){ $('.tt-dataset').append( '' +