javascript debugging
This commit is contained in:
parent
04684c5f65
commit
99131374cd
@ -52,6 +52,25 @@ def search_user():
|
||||
data = queries.do_user_search(searchword, terms)
|
||||
|
||||
# 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)
|
||||
|
||||
|
@ -8,7 +8,7 @@ $(document).ready(function() {
|
||||
var $hits = $('#hits');
|
||||
var $stats = $('#stats');
|
||||
var $facets = $('#facets');
|
||||
//var facets = [];
|
||||
//var facets = [];
|
||||
var $pagination = $('#pagination');
|
||||
var what = '';
|
||||
|
||||
@ -35,15 +35,15 @@ $(document).ready(function() {
|
||||
|
||||
// Input binding
|
||||
$inputField.on('keyup change', function() {
|
||||
var query = $inputField.val();
|
||||
var query = $inputField.val();
|
||||
|
||||
if(query === undefined) { return; }
|
||||
if(query === undefined) { return; }
|
||||
|
||||
toggleIconEmptyInput(!query.trim());
|
||||
// what could be like "/users"
|
||||
search.setQuery(query, what);
|
||||
//setURLParams(search);
|
||||
search.execute();
|
||||
toggleIconEmptyInput(!query.trim());
|
||||
// what could be like "/users"
|
||||
search.setQuery(query, what);
|
||||
// setURLParams(search);
|
||||
search.execute();
|
||||
}).focus();
|
||||
|
||||
search.on('results', function(content){
|
||||
@ -137,54 +137,54 @@ $(document).ready(function() {
|
||||
// If no results
|
||||
if (content.hits.length === 0) {
|
||||
$facets.empty();
|
||||
facets =[];
|
||||
facets =[];
|
||||
return;
|
||||
}
|
||||
|
||||
var storeValue = function (values, label){
|
||||
var storeValue = function (values, label){
|
||||
|
||||
|
||||
return function(item){
|
||||
return function(item){
|
||||
|
||||
let refined = search.isRefined(label, item.key);
|
||||
let refined = search.isRefined(label, item.key);
|
||||
|
||||
values.push({
|
||||
facet: label,
|
||||
label: item.key,
|
||||
value: item.key,
|
||||
count: item.doc_count,
|
||||
refined: refined,
|
||||
});
|
||||
};
|
||||
};
|
||||
values.push({
|
||||
facet: label,
|
||||
label: item.key,
|
||||
value: item.key,
|
||||
count: item.doc_count,
|
||||
refined: refined,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
var facets =[];
|
||||
var aggs = content.aggs;
|
||||
var facets =[];
|
||||
var aggs = content.aggs;
|
||||
|
||||
for (var label in aggs) {
|
||||
for (var label in aggs) {
|
||||
|
||||
let values = [];
|
||||
let values = [];
|
||||
|
||||
let buckets = aggs[label].buckets;
|
||||
let buckets = aggs[label].buckets;
|
||||
|
||||
if (buckets.length === 0) { continue; }
|
||||
if (buckets.length === 0) { continue; }
|
||||
|
||||
|
||||
|
||||
buckets.forEach(storeValue(values, label));
|
||||
buckets.forEach(storeValue(values, label));
|
||||
|
||||
facets.push({
|
||||
title: label,
|
||||
values: values.slice(0),
|
||||
});
|
||||
}
|
||||
facets.push({
|
||||
title: label,
|
||||
values: values.slice(0),
|
||||
});
|
||||
}
|
||||
|
||||
// Display facets
|
||||
var facetsHtml = '';
|
||||
|
||||
for (var indexFacet = 0; indexFacet < facets.length; ++indexFacet) {
|
||||
var facet = facets[indexFacet];
|
||||
//title, values[facet, value]
|
||||
//title, values[facet, value]
|
||||
facetsHtml += facetTemplate.render(facet);
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ $(document).ready(function() {
|
||||
}
|
||||
|
||||
var maxPages = 2;
|
||||
var nbPages = content.count / HITS_PER_PAGE;
|
||||
var nbPages = content.count / HITS_PER_PAGE;
|
||||
|
||||
// Process pagination
|
||||
var pages = [];
|
||||
@ -260,7 +260,7 @@ $(document).ready(function() {
|
||||
|
||||
$(document).on('click', '.toggleRefine', function() {
|
||||
search.toggleTerm($(this).data('facet'), $(this).data('value'));
|
||||
search.execute();
|
||||
search.execute();
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -5,137 +5,139 @@
|
||||
|
||||
var elasticSearcher = (function() {
|
||||
|
||||
var deze = {
|
||||
var deze = {
|
||||
|
||||
query:"",
|
||||
url:"",
|
||||
newhits: [],
|
||||
terms: {},
|
||||
page: 0,
|
||||
query:"",
|
||||
url:"",
|
||||
newhits: [],
|
||||
terms: {},
|
||||
page: 0,
|
||||
|
||||
setQuery: (function(q, _url){
|
||||
console.log('setQuery!: ' + q + 'what :'+ _url);
|
||||
deze.query=q;
|
||||
if (_url !== undefined) {
|
||||
deze.url=_url;
|
||||
}
|
||||
}),
|
||||
setQuery: (function(q, _url){
|
||||
console.log('setQuery!: ' + q + 'what :'+ _url);
|
||||
deze.query=q;
|
||||
if (_url !== undefined) {
|
||||
deze.url=_url;
|
||||
}
|
||||
}),
|
||||
|
||||
setCurrentPage: (function(page){
|
||||
if(page === undefined){
|
||||
return;
|
||||
}
|
||||
deze.page = page;
|
||||
}),
|
||||
setCurrentPage: (function(page){
|
||||
if(page === undefined){
|
||||
return;
|
||||
}
|
||||
deze.page = page;
|
||||
}),
|
||||
|
||||
//result callback
|
||||
results: (function(content){}),
|
||||
//result callback
|
||||
results: (function(content){}),
|
||||
|
||||
//error callback
|
||||
error: (function(message){
|
||||
console.log(message);
|
||||
}),
|
||||
//error callback
|
||||
error: (function(message){
|
||||
console.log(message);
|
||||
}),
|
||||
|
||||
on: (function(type, callback){
|
||||
deze[type] = callback;
|
||||
}),
|
||||
on: (function(type, callback){
|
||||
deze[type] = callback;
|
||||
}),
|
||||
|
||||
//parse the agg stuff
|
||||
aggs: (function(data){
|
||||
return deze.newhits.aggregations;
|
||||
}),
|
||||
//parse the agg stuff
|
||||
aggs: (function(data){
|
||||
return deze.newhits.aggregations;
|
||||
}),
|
||||
|
||||
toggleTerm: (function(term, value){
|
||||
if (deze.terms[term] !== undefined) {
|
||||
delete deze.terms[term];
|
||||
} else {
|
||||
deze.terms[term] = value;
|
||||
}
|
||||
}),
|
||||
toggleTerm: (function(term, value){
|
||||
if (deze.terms[term] !== undefined) {
|
||||
delete deze.terms[term];
|
||||
} else {
|
||||
deze.terms[term] = value;
|
||||
}
|
||||
}),
|
||||
|
||||
isRefined: (function(term, value){
|
||||
if (deze.terms[term] === value) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}),
|
||||
isRefined: (function(term, value){
|
||||
if (deze.terms[term] === value) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}),
|
||||
|
||||
//get response from elastic and rebuild json
|
||||
//so we can be a drop in of angolia
|
||||
execute: (function(){
|
||||
params = {
|
||||
q: deze.query,
|
||||
page: deze.page,
|
||||
};
|
||||
//add term filters
|
||||
Object.assign(params, deze.terms);
|
||||
//get response from elastic and rebuild json
|
||||
//so we can be a drop in of angolia
|
||||
execute: (function(){
|
||||
params = {
|
||||
q: deze.query,
|
||||
page: deze.page,
|
||||
};
|
||||
//add term filters
|
||||
Object.assign(params, deze.terms);
|
||||
|
||||
var pstr = jQuery.param( params );
|
||||
var pstr = jQuery.param( params );
|
||||
|
||||
var jqxhr = $.getJSON("/api/newsearch" + deze.url + "?"+ pstr, function( data ) {
|
||||
let hits = data.hits.hits;
|
||||
var newhits = hits.map(function(hit){
|
||||
return hit._source;
|
||||
});
|
||||
var jqxhr = $.getJSON("/api/newsearch" + deze.url + "?"+ pstr, function( data ) {
|
||||
let hits = data.hits.hits;
|
||||
var newhits = hits.map(function(hit){
|
||||
return hit._source;
|
||||
});
|
||||
|
||||
deze.newhits = newhits.slice(0);
|
||||
//cb(newhits.slice(0));
|
||||
deze.results({
|
||||
'count': data.hits.total,
|
||||
'hits': newhits.slice(0),
|
||||
'took': data.took,
|
||||
'page': deze.page,
|
||||
'aggs': data.aggregations,
|
||||
});
|
||||
});
|
||||
deze.newhits = newhits.slice(0);
|
||||
//cb(newhits.slice(0));
|
||||
deze.results({
|
||||
'count': data.hits.total,
|
||||
'hits': newhits.slice(0),
|
||||
'took': data.took,
|
||||
'page': deze.page,
|
||||
'aggs': data.aggregations,
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
execute: deze.execute,
|
||||
on: deze.on,
|
||||
setQuery: deze.setQuery,
|
||||
setCurrentPage: deze.setCurrentPage,
|
||||
query: deze.query,
|
||||
page: deze.page,
|
||||
toggleTerm: deze.toggleTerm,
|
||||
isRefined: deze.isRefined,
|
||||
};
|
||||
return {
|
||||
execute: deze.execute,
|
||||
on: deze.on,
|
||||
setQuery: deze.setQuery,
|
||||
setCurrentPage: deze.setCurrentPage,
|
||||
query: deze.query,
|
||||
page: deze.page,
|
||||
toggleTerm: deze.toggleTerm,
|
||||
isRefined: deze.isRefined,
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
|
||||
var elasticSearch = (function($, url) {
|
||||
return function findMatches(q, cb, async){
|
||||
if (!cb) { return; }
|
||||
$.fn.getSearch(q, cb, async, url);
|
||||
};
|
||||
if (!cb) { return; }
|
||||
$.fn.getSearch(q, cb, async, url);
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
|
||||
(function( $ ){
|
||||
|
||||
$.fn.getSearch = function(q, cb, async, url){
|
||||
$.fn.getSearch = function(q, cb, async, url){
|
||||
|
||||
let newhits = [];
|
||||
if(url === undefined){
|
||||
url = '';
|
||||
}
|
||||
let newhits = [];
|
||||
if(url === undefined){
|
||||
url = '';
|
||||
}
|
||||
|
||||
console.log('searching! '+ url + q);
|
||||
console.log('searching! '+ url + ' q= ' + q);
|
||||
|
||||
$.getJSON("/api/newsearch" + url + "?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));
|
||||
});
|
||||
};
|
||||
$.getJSON("/api/newsearch" + url + "?q=" + q, function( data ) {
|
||||
let hits = data.hits.hits;
|
||||
newhits = hits.map(function(hit){
|
||||
return hit._source;
|
||||
});
|
||||
cb(newhits.slice(0));
|
||||
if(async !== undefined){
|
||||
async(newhits.slice(0));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
}(jQuery));
|
||||
@ -143,100 +145,101 @@ var elasticSearch = (function($, url) {
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
var searchInput = $('#cloud-search');
|
||||
var searchInput = $('#cloud-search');
|
||||
|
||||
var tu = searchInput.typeahead({hint: true}, {
|
||||
//source: algoliaIndex.ttAdapter(),
|
||||
source: elasticSearch($),
|
||||
async: true,
|
||||
displayKey: 'name',
|
||||
limit: 9, // Above 10 it stops working from
|
||||
// some magic reason
|
||||
minLength: 0,
|
||||
templates: {
|
||||
suggestion: function(hit) {
|
||||
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 hitPicture;
|
||||
var tu = searchInput.typeahead({hint: true}, {
|
||||
//source: algoliaIndex.ttAdapter(),
|
||||
source: elasticSearch($),
|
||||
async: true,
|
||||
displayKey: 'name',
|
||||
limit: 9, // Above 10 it stops working from
|
||||
// some magic reason
|
||||
minLength: 0,
|
||||
templates: {
|
||||
suggestion: function(hit) {
|
||||
console.log('hit!');
|
||||
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 hitPicture;
|
||||
|
||||
if (hit.picture){
|
||||
hitPicture = '<img src="' + hit.picture + '"/>';
|
||||
} else {
|
||||
hitPicture = '<div class="search-hit-thumbnail-icon">';
|
||||
hitPicture += (hit.media ? '<i class="pi-' + hit.media + '"></i>' : '<i class="dark pi-'+ hit.node_type + '"></i>');
|
||||
hitPicture += '</div>';
|
||||
}
|
||||
var $span = $('<span>').addClass('project').text(hit.project.name);
|
||||
var $searchHitName = $('<div>').addClass('search-hit-name')
|
||||
.attr('title', hit.name)
|
||||
.text(hit.name);
|
||||
if (hit.picture){
|
||||
hitPicture = '<img src="' + hit.picture + '"/>';
|
||||
} else {
|
||||
hitPicture = '<div class="search-hit-thumbnail-icon">';
|
||||
hitPicture += (hit.media ? '<i class="pi-' + hit.media + '"></i>' : '<i class="dark pi-'+ hit.node_type + '"></i>');
|
||||
hitPicture += '</div>';
|
||||
}
|
||||
var $span = $('<span>').addClass('project').text(hit.project.name);
|
||||
var $searchHitName = $('<div>').addClass('search-hit-name')
|
||||
.attr('title', hit.name)
|
||||
.text(hit.name);
|
||||
|
||||
return '' +
|
||||
'<a href="/nodes/'+ hit.objectID + '/redir" class="search-site-result" id="'+ hit.objectID + '">' +
|
||||
'<div class="search-hit">' +
|
||||
'<div class="search-hit-thumbnail">' +
|
||||
hitPicture +
|
||||
hitFree +
|
||||
'</div>' +
|
||||
$searchHitName.html() +
|
||||
'<div class="search-hit-meta">' +
|
||||
$span.html() + ' · ' +
|
||||
'<span class="node_type">' + hit.node_type + '</span>' +
|
||||
hitMedia +
|
||||
'</div>' +
|
||||
'</div>'+
|
||||
'</a>';
|
||||
}
|
||||
}
|
||||
});
|
||||
return '' +
|
||||
'<a href="/nodes/'+ hit.objectID + '/redir" class="search-site-result" id="'+ hit.objectID + '">' +
|
||||
'<div class="search-hit">' +
|
||||
'<div class="search-hit-thumbnail">' +
|
||||
hitPicture +
|
||||
hitFree +
|
||||
'</div>' +
|
||||
$searchHitName.html() +
|
||||
'<div class="search-hit-meta">' +
|
||||
$span.html() + ' · ' +
|
||||
'<span class="node_type">' + hit.node_type + '</span>' +
|
||||
hitMedia +
|
||||
'</div>' +
|
||||
'</div>'+
|
||||
'</a>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('.search-site-result.advanced, .search-icon').on('click', function(e){
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
window.location.href = '/search?q='+ $("#cloud-search").val() + '&page=1';
|
||||
});
|
||||
$('.search-site-result.advanced, .search-icon').on('click', function(e){
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
window.location.href = '/search?q='+ $("#cloud-search").val() + '&page=1';
|
||||
});
|
||||
|
||||
|
||||
searchInput.bind('typeahead:select', function(ev, hit) {
|
||||
$('.search-icon').removeClass('pi-search').addClass('pi-spin spin');
|
||||
searchInput.bind('typeahead:select', function(ev, hit) {
|
||||
$('.search-icon').removeClass('pi-search').addClass('pi-spin spin');
|
||||
|
||||
window.location.href = '/nodes/'+ hit.objectID + '/redir';
|
||||
});
|
||||
window.location.href = '/nodes/'+ hit.objectID + '/redir';
|
||||
});
|
||||
|
||||
searchInput.bind('typeahead:active', function() {
|
||||
$('#search-overlay').addClass('active');
|
||||
$('.page-body').addClass('blur');
|
||||
});
|
||||
searchInput.bind('typeahead:active', function() {
|
||||
$('#search-overlay').addClass('active');
|
||||
$('.page-body').addClass('blur');
|
||||
});
|
||||
|
||||
searchInput.bind('typeahead:close', function() {
|
||||
$('#search-overlay').removeClass('active');
|
||||
$('.page-body').removeClass('blur');
|
||||
});
|
||||
searchInput.bind('typeahead:close', function() {
|
||||
$('#search-overlay').removeClass('active');
|
||||
$('.page-body').removeClass('blur');
|
||||
});
|
||||
|
||||
searchInput.keyup(function(e) {
|
||||
if ( $('.tt-dataset').is(':empty') ){
|
||||
if(e.keyCode == 13){
|
||||
window.location.href = '/search#q='+ $("#cloud-search").val() + '&page=1';
|
||||
}
|
||||
}
|
||||
});
|
||||
searchInput.keyup(function(e) {
|
||||
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) {
|
||||
if( suggestions != undefined && $('.tt-all-results').length <= 0){
|
||||
$('.tt-dataset').append(
|
||||
'<a id="search-advanced" href="/search?q='+ $("#cloud-search").val() + '&page=1" class="search-site-result advanced tt-suggestion">' +
|
||||
'<div class="search-hit">' +
|
||||
'<div class="search-hit-thumbnail">' +
|
||||
'<div class="search-hit-thumbnail-icon">' +
|
||||
'<i class="pi-search"></i>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="search-hit-name">' +
|
||||
'Use Advanced Search' +
|
||||
'</div>' +
|
||||
'</div>'+
|
||||
'</a>');
|
||||
}
|
||||
});
|
||||
searchInput.bind('typeahead:render', function(event, suggestions, async, dataset) {
|
||||
if( suggestions != undefined && $('.tt-all-results').length <= 0){
|
||||
$('.tt-dataset').append(
|
||||
'<a id="search-advanced" href="/search?q='+ $("#cloud-search").val() + '&page=1" class="search-site-result advanced tt-suggestion">' +
|
||||
'<div class="search-hit">' +
|
||||
'<div class="search-hit-thumbnail">' +
|
||||
'<div class="search-hit-thumbnail-icon">' +
|
||||
'<i class="pi-search"></i>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="search-hit-name">' +
|
||||
'Use Advanced Search' +
|
||||
'</div>' +
|
||||
'</div>'+
|
||||
'</a>');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -6,10 +6,10 @@
|
||||
this.autocomplete({hint: false}, [
|
||||
{
|
||||
source: elasticSearch($, '/user'),
|
||||
displayKey: 'full_name',
|
||||
async: true,
|
||||
displayKey: 'full_name',
|
||||
//async: true,
|
||||
minLength: 1,
|
||||
limit: 10,
|
||||
limit: 9,
|
||||
templates: {
|
||||
suggestion: function (hit) {
|
||||
var suggestion = hit.full_name + ' (' + hit.username + ')';
|
||||
|
Loading…
x
Reference in New Issue
Block a user