diff --git a/pillar/api/search/documents.py b/pillar/api/search/documents.py index 2638479f..0c3d5249 100644 --- a/pillar/api/search/documents.py +++ b/pillar/api/search/documents.py @@ -51,22 +51,29 @@ class Node(es.DocType): analyzer=autocomplete ) - user_id = es.Keyword() - user_name = es.String( - fielddata=True, - analyzer=autocomplete - ) + user = es.Object({ + 'fields': { + 'id': es.Keyword(), + 'name': es.String( + fielddata=True, + analyzer=autocomplete) + } + }) description = es.String() is_free = es.Boolean() - project_id = es.Keyword() - project_name = es.String() + project = es.Object({ + 'fields': { + 'id': es.Keyword(), + 'name': es.Keyword(), + } + }) media = es.Keyword() - picture_url = es.Keyword() + picture = es.Keyword() tags = es.Keyword(multi=True) license_notes = es.String() @@ -92,15 +99,15 @@ def create_doc_from_node_data(node_to_index): doc.node_type = node_to_index['node_type'] doc.name = node_to_index['name'] - doc.user_id = str(node_to_index['user']['_id']) - doc.user_name = node_to_index['user']['full_name'] - doc.project_id = str(node_to_index['project']['_id']) - doc.project_name = node_to_index['project']['name'] + doc.user.id = str(node_to_index['user']['_id']) + doc.user.name = node_to_index['user']['full_name'] + doc.project.id = str(node_to_index['project']['_id']) + doc.project.name = node_to_index['project']['name'] if node_to_index['node_type'] == 'asset': doc.media = node_to_index['media'] - doc.picture_url = node_to_index.get('picture') + doc.picture = node_to_index.get('picture') doc.tags = node_to_index.get('tags') doc.license_notes = node_to_index.get('license_notes') diff --git a/pillar/api/search/queries.py b/pillar/api/search/queries.py index 9aaa7bbf..26d7698d 100644 --- a/pillar/api/search/queries.py +++ b/pillar/api/search/queries.py @@ -24,8 +24,10 @@ def do_search(query: str) -> dict: """ should = [ Q('match', name=query), - Q('match', user_name=query), - Q('match', project_name=query), + + {"match": {"project.name": query}}, + {"match": {"user.name": query}}, + Q('match', description=query), Q('term', media=query), Q('term', tags=query), diff --git a/src/scripts/tutti/4_search.js b/src/scripts/tutti/4_search.js index 9c53603c..63ae6834 100644 --- a/src/scripts/tutti/4_search.js +++ b/src/scripts/tutti/4_search.js @@ -5,46 +5,38 @@ $(document).ready(function() { - if (typeof algoliaIndex === 'undefined') return; + var getSearch = function(q, cb, async){ + let newhits = []; + $.getJSON("/api/newsearch?q=" + q, function( data ) { + let hits = data.hits.hits; + newhits = hits.map(function(hit){ + return hit._source; + }); + cb(newhits.slice(0)); + async(newhits.slice(0)); + }); + }; - var elasticSearch = function() { - - console.log('yay'); + var elasticSearch = (function() { 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); + if (!cb) { return; } + getSearch(q, cb, async); }; + }); - }; var searchInput = $('#cloud-search'); var tu = searchInput.typeahead({hint: true}, { //source: algoliaIndex.ttAdapter(), source: elasticSearch(), + //source: elkBlood(), + async: true, 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; @@ -55,7 +47,7 @@ $(document).ready(function() { hitPicture = '
'; hitPicture += (hit.media ? '' : ''); hitPicture += '
'; - }; + } var $span = $('').addClass('project').text(hit.project.name); var $searchHitName = $('
').addClass('search-hit-name') .attr('title', hit.name) @@ -104,18 +96,14 @@ $(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'; - }; - }; + } + } }); 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( '' + @@ -130,7 +118,7 @@ $(document).ready(function() { '
' + ''+ ''); - }; + } }); });