2017-07-27 10:09:33 +02:00
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
2017-11-04 13:34:05 +01:00
|
|
|
$('#loading').hide()
|
|
|
|
|
|
2019-07-17 12:55:47 +02:00
|
|
|
$('#info').click( function() {
|
|
|
|
|
console.log("click");
|
|
|
|
|
$('#info-search').toggle();
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-04 13:34:05 +01:00
|
|
|
$('#search').submit(function(e) {
|
2017-07-27 10:09:33 +02:00
|
|
|
e.preventDefault();
|
|
|
|
|
args = $(this).serialize();
|
2017-11-04 13:34:05 +01:00
|
|
|
$('#graph').empty();
|
|
|
|
|
$('#results').empty();
|
|
|
|
|
|
2019-12-09 13:40:21 +01:00
|
|
|
console.log('/search?'+ args)
|
|
|
|
|
|
2017-11-04 13:34:05 +01:00
|
|
|
$('#loading').show()
|
2017-11-06 14:11:18 +01:00
|
|
|
$.get('/search?'+ args, function(data) {
|
2017-11-04 13:34:05 +01:00
|
|
|
$('#loading').hide()
|
2019-07-12 11:47:36 +02:00
|
|
|
// console.log(data);
|
2017-11-04 13:34:05 +01:00
|
|
|
// $('#graph').empty();
|
|
|
|
|
// $('#results').empty();
|
2017-07-27 10:09:33 +02:00
|
|
|
$.each(data.result, function(i, item) {
|
|
|
|
|
search_result_archive(item);
|
|
|
|
|
});
|
2017-11-04 13:34:05 +01:00
|
|
|
graph(data);
|
2017-07-27 10:09:33 +02:00
|
|
|
});
|
|
|
|
|
});
|
2017-11-04 13:34:05 +01:00
|
|
|
|
2017-07-27 10:09:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function search_result_archive(a) {
|
|
|
|
|
$('<div/>', {
|
|
|
|
|
id: a.archive,
|
|
|
|
|
class: "archive",
|
|
|
|
|
}).appendTo('#results');
|
|
|
|
|
$('#' + a.archive).append("<h3>" + a.archive + "</h3>");
|
|
|
|
|
$.each(a.results, function(i, r) {
|
|
|
|
|
$('<ul/>', {
|
|
|
|
|
id: r.thread + "-" + a.archive,
|
|
|
|
|
text: r.thread.replace('_', ' ')
|
|
|
|
|
}).appendTo('#' + a.archive);
|
|
|
|
|
let hits = "<ul>";
|
2017-11-24 09:52:14 +01:00
|
|
|
|
2017-07-27 10:09:33 +02:00
|
|
|
$.each(r.hits, function(j, h){
|
2019-07-12 11:54:46 +02:00
|
|
|
// console.log(h)
|
2019-07-17 12:55:47 +02:00
|
|
|
let hit = '<li><a href="' + h.url+ '" target="_blank">' + h.subject + '</a> -- <i>' + h.author_name + '</i></li>';
|
2017-07-27 10:09:33 +02:00
|
|
|
hits += hit;
|
|
|
|
|
});
|
|
|
|
|
hits += "</ul>";
|
|
|
|
|
$('#' + r.thread + "-" + a.archive).append(hits);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 16:18:10 +01:00
|
|
|
var min_month = new Date(1995, 9);
|
2017-07-27 10:09:33 +02:00
|
|
|
var max_month = new Date();
|
|
|
|
|
|
|
|
|
|
function diff_months(d1, d2) {
|
|
|
|
|
var months;
|
|
|
|
|
months = (d2.getFullYear() - d1.getFullYear()) * 12;
|
|
|
|
|
months -= d1.getMonth();
|
|
|
|
|
months += d2.getMonth();
|
|
|
|
|
return months <= 0 ? 0 : months;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function format(date) {
|
|
|
|
|
var month_names = [
|
|
|
|
|
"Jan", "Feb", "Mar",
|
|
|
|
|
"Apr", "May", "Jun", "Jul",
|
|
|
|
|
"Aug", "Sep", "Oct",
|
|
|
|
|
"Nov", "Dec"
|
|
|
|
|
];
|
|
|
|
|
return month_names[date.getMonth()] + ' ' + date.getFullYear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function graph(data) {
|
|
|
|
|
var d = diff_months(min_month, max_month);
|
|
|
|
|
var vec = new Array();
|
|
|
|
|
for(let ar of data.result) {
|
|
|
|
|
let ar_vec = new Array(d + 1).fill(0);
|
|
|
|
|
ar_vec[0] = ar.archive;
|
|
|
|
|
for(let r of ar.results) {
|
|
|
|
|
let date = new Date(Date.parse(r.thread.replace("_", " 1, "))); // this may blow...
|
|
|
|
|
let index = diff_months(min_month, date);
|
|
|
|
|
ar_vec[index + 1] = r.nbr_hits;
|
|
|
|
|
}
|
|
|
|
|
vec.push(ar_vec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var x_axis = new Array(d);
|
|
|
|
|
for (let i = 0; i < d; i++) {
|
|
|
|
|
let d = new Date(min_month.getFullYear(), min_month.getMonth());
|
|
|
|
|
d.setMonth(d.getMonth() + i);
|
|
|
|
|
x_axis[i] = format(d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(vec);
|
|
|
|
|
|
|
|
|
|
var chart = c3.generate({
|
|
|
|
|
bindto: '#graph',
|
|
|
|
|
data: {
|
|
|
|
|
columns: vec,
|
|
|
|
|
type: 'bar'
|
|
|
|
|
},
|
|
|
|
|
axis: {
|
|
|
|
|
x: {
|
|
|
|
|
type: 'category',
|
|
|
|
|
categories: x_axis,
|
|
|
|
|
tick: {
|
|
|
|
|
culling: {
|
|
|
|
|
max: 15
|
|
|
|
|
},
|
|
|
|
|
multiline:false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
bar: {
|
|
|
|
|
width: {
|
2017-11-08 16:18:10 +01:00
|
|
|
ratio: 0.8
|
2017-07-27 10:09:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|