function doSearch() {
var match_act=document.getElementById("match_act").value;
var select_act=document.getElementById("select_act").value;
var searchstring=document.getElementById("key").value;
var querytime = new Date()["getTime"]();
if (searchstring["length"] < 4) {
alert("关键字长度请大于4!!");
return false
};
hideErrorMessage("#error-container");
event.preventDefault();
var data = buildSearchQuery(match_act,select_act,searchstring);
$.ajax({
url: '/ajax.php',
type: 'POST',
contentType: 'application/json; charset=UTF-8',
crossDomain: true,
dataType: 'json',
data: JSON.stringify(data),
success: function(response) {
var tableObj = document["getElementById"]("value_tables");
var source = response.hits.hits;
var count = response.hits.total;
var result=[];
if (count > 0) {
$("#selecting")["css"]("display", "block");
$("#somd5_table")["css"]("display", "block");
if (count >=100) {
alert("查询到的数据太多,只显示100条,请尽量输入准确的关键词")
count=100;
}
for (var i = 0; i < count; i++) {
data=source[i]['_source'];
result.push('
';
$(container).html(error_box);
$(container).hide();
$(container).slideDown("fast", function() {});
if(auto_hide){
$(container).delay(hide_timeout).fadeOut('slow');
}
}
function hideErrorMessage(container){
//$(container).html('');
$(container).slideUp("fast", function() {});
//$(container).hide();
}
$(document).ready(function(){
//Change the icon of the text box as the user types
$( ".searchfield" ).keyup(function() {
toggleSearchButton();
});
//If button is clicked when there is text in it,
//clear text and show folders
$(".input-group-addon").on('click', function (e) {
if ($('.searchfield').val()) {
$('.searchfield').val("");
toggleSearchButton();
}
});
//Process the search
$("form").on("submit", function(event){
if ($('.searchfield').val()) {
doSearch($('.searchfield').val());
}else{
return false;
}
});
});
//Function toggles between the search results and the folders structure
function toggleSearchButton(){
if ($('.searchfield').val()) {
//Change the icon to show the cross instead of the search icon
$('#textbox-icon').removeClass('fa fa-search').addClass('fa fa-times');
//hide the documents tree
//$('#jstree').fadeOut( "slow", function() {});
}else{
$('#results').html('');
//Change the icon to show the search instead of the cross
$('#textbox-icon').removeClass('fa fa-times').addClass('fa fa-search');
//hide the documents tree
//$('#jstree').fadeIn( "slow", function() {});
}
}