javascript debugging

This commit is contained in:
2017-12-29 14:52:39 +01:00
parent 04684c5f65
commit 99131374cd
4 changed files with 245 additions and 223 deletions

View File

@@ -52,6 +52,25 @@ def search_user():
data = queries.do_user_search(searchword, terms) data = queries.do_user_search(searchword, terms)
# filter sensitive stuff # filter sensitive stuff
# we only need. objectID, full_name, username
hits = data.get('hits')
new_hits = []
for hit in hits.get('hits'):
source = hit['_source']
single_hit = {
'_source': {
'objectID': source.get('objectID'),
'username': source.get('username'),
'full_name': source.get('full_name'),
}
}
new_hits.append(single_hit)
# replace search result with safe subset
data['hits']['hits'] = new_hits
return jsonify(data) return jsonify(data)

View File

@@ -125,15 +125,17 @@ var elasticSearch = (function($, url) {
url = ''; url = '';
} }
console.log('searching! '+ url + q); console.log('searching! '+ url + ' q= ' + q);
$.getJSON("/api/newsearch" + url + "?q=" + q, function( data ) { $.getJSON("/api/newsearch" + url + "?q=" + q, function( data ) {
let hits = data.hits.hits; let hits = data.hits.hits;
newhits = hits.map(function(hit){ newhits = hits.map(function(hit){
return hit._source; return hit._source;
}); });
//cb(newhits.slice(0)); cb(newhits.slice(0));
if(async !== undefined){
async(newhits.slice(0)); async(newhits.slice(0));
}
}); });
}; };
@@ -155,6 +157,7 @@ $(document).ready(function() {
minLength: 0, minLength: 0,
templates: { templates: {
suggestion: function(hit) { suggestion: function(hit) {
console.log('hit!');
var hitMedia = (hit.media ? ' · <span class="media">'+hit.media+'</span>' : ''); var hitMedia = (hit.media ? ' · <span class="media">'+hit.media+'</span>' : '');
var hitFree = (hit.is_free ? '<div class="search-hit-ribbon"><span>free</span></div>' : ''); var hitFree = (hit.is_free ? '<div class="search-hit-ribbon"><span>free</span></div>' : '');
var hitPicture; var hitPicture;

View File

@@ -7,9 +7,9 @@
{ {
source: elasticSearch($, '/user'), source: elasticSearch($, '/user'),
displayKey: 'full_name', displayKey: 'full_name',
async: true, //async: true,
minLength: 1, minLength: 1,
limit: 10, limit: 9,
templates: { templates: {
suggestion: function (hit) { suggestion: function (hit) {
var suggestion = hit.full_name + ' (' + hit.username + ')'; var suggestion = hit.full_name + ' (' + hit.username + ')';