').addClass('hidden').appendTo(bubble);
dot.appendTo(chat);
scroller.down();
$("#chat-search-button").addClass('hidden');
$("#stop-button").removeClass('hidden');
replaceQueryParam('page', 1);
replaceQueryParam('q', q);
xhr = $.ajax({
type: "POST",
dataType: "text",
timeout : 60000,
url: endpoint,
data : {q: encodeURIComponent(q)},
processData: true,
xhrFields: {
onprogress: function(e)
{
scroller.canShowGodown = false;
var response = e.currentTarget.response;
chat.html(addCodeCopyButton(sanitizeInput(converter.makeHtml(unescapeHtml(response)))));
hljs.highlightAll();
scroller.bottom();
}
},
success: function(data) {
$(document).ready(function(){$('#conversation').find('a').attr('target', '_blank');});
$("#chat-search-button").removeClass('hidden');
$("#stop-button").addClass('hidden');
scroller.bottom();
scroller.canShowGodown = true;
// show contextual links only when the answer is complete
refs.fadeIn(300);//.removeClass('hidden');
},
error: function(jqXhr, textStatus, errorMessage) {
console.log(errorMessage);
chat.append("
Your request has been interrupted
");
$("#chat-search-button").removeClass('hidden');
$("#stop-button").addClass('hidden');
scroller.bottom();
scroller.canShowGodown = true;
},
});
}
function get_references(q){
$.ajax({
type: "GET",
dataType: "json",
contentType: 'application/json',
url: references,
data : {q: encodeURIComponent(q)},
processData: true,
success: function(data) {
var jsonData = JSON.parse(data);
jsonData.forEach(function(ref){
lnk = $('
',{class: "inline-block text-redis-ink-900 bg-redis-yellow-100 border border-redis-pen-300 no-underline hover:underline rounded-md px-1.5 pt-1 pb-1/2 m-1", text: ref.title, title: ref.title, href: ref.url, target: "_blank"}).appendTo(refs);
});
scroller.bottom();
}
});
}
function get_search(q, page=1){
if ((q == null) || (q.trim().length == 0)){return;}
question = q.trim();
var deselectedCheckboxValues = [];
var deselectedCheckboxValues = $('#facets input:checkbox:not(:checked)').map(function () {
return this.value;
}).get();
$.ajax({
type: "GET",
dataType: "json",
contentType: 'application/json',
url: search,
//data : JSON.stringify({q:encodeURIComponent(q), page:page, tags:deselectedCheckboxValues}),
data : {q:encodeURIComponent(q), page:page, tags:deselectedCheckboxValues.join(',')},
processData: true,
success: function(data) {
$("#search").empty();
if (data['data'].length>0){
$(".outcome").addClass("hidden");
data['data'].forEach(function(ref){
p = $('');
$('',{class: "text-redis-red-600 hover:underline hover-text-redis-red-500",text: ref.title, title: ref.title, href: ref.url, target: "_blank"}).appendTo(p);
$('').addClass('summary').html(ref.content.substring(0, 300)).appendTo(p);
p.appendTo($("#search"));
});
$("#search").append(data['pagination']);
}
else {
$(".outcome").removeClass("hidden");
}
// update partial results in the faceted search box
Object.entries(data['agg']).forEach(([key, value]) => {
$(`#${key}`).text(`${value}`);
});
$("a.page-link").click(function(e){
e.preventDefault();
var urlParams = new URLSearchParams($(this).attr("href"));
var q = urlParams.get('q');
var page = urlParams.get('page')==null?1:urlParams.get('page');
replaceQueryParam('page', page);
replaceQueryParam('q', q);
get_search(q, page)
});
},
error: function(data) {
console.log(data.responseText);
}
});
}
}