Skip to content

Commit

Permalink
Фильтр по полям, логирование поисковых запросов
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris committed Nov 19, 2024
1 parent bd7818b commit 12f7272
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
44 changes: 29 additions & 15 deletions front/assets/js/app-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ var mapping = [];
var fmapping = {};
var filter_operation = ["is", "is_not", "exists", "does_not_exists"]
var filters_set = {}
dateS.setMinutes(dateS.getMinutes() - 195)
dateE.setMinutes(dateE.getMinutes() - 180)
//dateS.setMinutes(dateS.getMinutes() - 195)
dateS.setMinutes(dateS.getMinutes() - 15)
//dateE.setMinutes(dateE.getMinutes() - 180)
//dateE.setMinutes(dateE.getMinutes() - 180)
$.datetimepicker.setLocale('ru');
$('#datetimepicker_start').datetimepicker({timepicker: true, format:'Y-m-d H:i:s', step: 15, value:dateS});
$('#datetimepicker_start').datetimepicker({timepicker: true, format:'Y-m-d H:i:s', step: 15, value:dateS.toISOString()});
$('#datetimepicker_end').datetimepicker({
timepicker: true,
format:'Y-m-d H:i:s',
step: 15,
value:dateE,
value:dateE.toISOString(),
onShow:function( ct ){
this.setOptions({
minDate:$('#datetimepicker_start').val()?$('#datetimepicker_start').val():false
Expand All @@ -22,6 +24,22 @@ $('#datetimepicker_end').datetimepicker({
//var getnodes = setInterval(NodeStatus, 5000);
//var getindices = setInterval(IndexList, 3000);


function cyrb53(str, seed = 0){
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
for(let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);

return 4294967296 * (2097151 & h2) + (h1 >>> 0);
}

function bytesToSize(bytes) {
var sizes = ['b', 'kb', 'mb', 'gb', 'tb'];
if (bytes == 0) return '0 byte';
Expand Down Expand Up @@ -103,29 +121,25 @@ $('#igs').on('change', function(e) {
$('#mapping_filter').val('');
str += "<ul class='list-group'>"
for (var k in data) {
// <li class="list-group-item" style="">
// <input type="checkbox" name="fields" id="mappingkubernetes.namespace_labels.extended-monitoring_deckhouse_io/enabled" data-type="text" value="kubernetes.namespace_labels.extended-monitoring_deckhouse_io/enabled" >
// &nbsp;<label for="mappingkubernetes.namespace_labels.extended-monitoring_deckhouse_io/enabled" style="word-wrap: break-word !important;word-break: break-word;">kubernetes.namespace_labels.extended-monitoring_deckhouse_io/enabled&nbsp;&nbsp;(text)</label>
// </li>
str += "<li class='list-group-item' style='word-wrap: break-word !important; word-break: break-word;display: flex;align-items: flex-start;'><input type='checkbox' name='fields' id='mapping_"+k+"' data-type='" + data[k] + "' value='" + k + "' style='margin-top: 6px;'>&nbsp;<label for='mapping_"+k+"'>"+ k + "&nbsp;&nbsp;(" + data[k] + ")" +"</label></li>";
str += "<li class='list-group-item' style='word-wrap: break-word !important; word-break: break-word;display: flex;align-items: flex-start;' id='m_"+cyrb53(k)+"'><input type='checkbox' name='fields' id='mapping_"+k+"' data-type='" + data[k] + "' value='" + k + "' style='margin-top: 6px;'>&nbsp;<label for='mapping_"+k+"'>"+ k + "&nbsp;&nbsp;(" + data[k] + ")" +"</label></li>";
mapping.push(k);
}
fmapping = data;
str += "</ul>"
$("#fields").html(str);
event.preventDefault();
}
});
});

$('#mapping_filter').on('keypress', function(e) {
var str="";
str += "<ul class='list-group'>"
for (var k in fmapping) {
if (k.includes(e.target.value))
str += "<li class='list-group-item' style='word-wrap: break-word !important; word-break: break-word;display: flex;align-items: flex-start;'><input type='checkbox' name='fields' id='mapping_"+k+"' data-type='" + fmapping[k] + "' value='" + k + "' style='margin-top: 6px;'>&nbsp;<label for='mapping_"+k+"'>"+ k + "</label></li>";
if (k.includes(e.target.value)) {
$('#m_'+cyrb53(k)).show();
} else {
$('#m_'+cyrb53(k)).hide();
}
}
str += "</ul>"
$("#fields").html(str);
});

$('#modal_add_filter').on('shown.bs.modal',function(e){
Expand Down
2 changes: 0 additions & 2 deletions modules/router/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ func (rt *Router) getIndexGroups(cluster string) ([]indexGroup, error) {
return nil, err
}
err = json.Unmarshal(response, &igs)
fmt.Printf("%v\n", igs)
if err != nil {
return nil, err
}
Expand All @@ -246,7 +245,6 @@ func (rt *Router) getIndexGroups(cluster string) ([]indexGroup, error) {
igresp = append(igresp, n)
}
unique := removeDuplicates(igresp)
fmt.Printf("%v\n", unique)
return unique, nil

}
Expand Down
3 changes: 2 additions & 1 deletion modules/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,8 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
query = fmt.Sprintf(`"query": { "bool": { "must": [ %s ],"filter": [ %s %s ], "should": [],"must_not": [ %s ] }}`, xql, tf, filters, must_not)

full_query = fmt.Sprintf(`{"size": 500, %s, %s, %s, %s }`, sort, use_source, fields, query)
fmt.Println(full_query)
if request.Search.Count {
log.Println("action: Count", "\tquery: ", "{"+query+"}")
_ = json.Unmarshal([]byte("{"+query+"}"), &req)
cresponse, err := rt.doPost(host+request.Search.Index+"/_count", req, "Search")
if err != nil {
Expand All @@ -695,6 +695,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
}
w.Write(cresponse)
} else {
log.Println("action: Search", "\tquery: ", full_query)
_ = json.Unmarshal([]byte(full_query), &req)
sresponse, err := rt.doPost(host+request.Search.Index+"/_search", req, "Search")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion modules/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

package version

var Version = "extractor/v0.2.15"
var Version = "extractor/v0.2.16"

0 comments on commit 12f7272

Please sign in to comment.