Skip to content
This repository was archived by the owner on Jan 8, 2019. It is now read-only.

Commit 95f85c4

Browse files
author
Lennart Koopmann
committed
link explaining search result highlighting. fixes #762
1 parent 26cdb17 commit 95f85c4

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

app/views/sidebars/searchresults.scala.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ <h4>Quick select fields</h4>
6464
<div class="result-highlight-control" style="display: none">
6565
<input type="checkbox" class="toggle-result-highlight" id="toggle-highlighting" checked /> <label for="toggle-highlighting">Highlight matches</label>
6666
</div>
67+
68+
<div class="explain-result-highlight-control" style="display: none">
69+
<i class="icon icon-lightbulb"></i>
70+
Learn about search result highlighting
71+
<a href="http://support.torch.sh/help/kb/graylog2-web-interface/search-result-highlighting" target="_blank">here</a>.
72+
</div>
73+
6774
}
6875

6976
<div id="used-indices" class="modal hide fade" tabindex="-1" role="dialog">

public/javascripts/universalsearch.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,30 @@ $(document).ready(function() {
9292
};
9393
$(".messages tbody tr").each(function() {
9494
var ranges = $(this).data('highlight');
95-
for (var field in ranges) {
96-
if (! ranges.hasOwnProperty(field) ) {
97-
continue;
98-
}
99-
var positions = ranges[field];
100-
var fieldNameHash = CryptoJS.MD5(field);
101-
$(".result-td-" + fieldNameHash, $(this)).each(function(){
102-
var elemText = $(this).text();
103-
for (var idx = positions.length - 1; idx >= 0; idx--) {
104-
var range = positions[idx];
105-
elemText = elemText.gl2_splice(range.start + range.length, "</span>");
106-
elemText = elemText.gl2_splice(range.start, '<span class="result-highlight">');
95+
96+
if (ranges == undefined) {
97+
// Search highlighting not enabled in server.
98+
$(".explain-result-highlight-control").show();
99+
} else {
100+
// Search highlighting is enabled in server.
101+
for (var field in ranges) {
102+
if (! ranges.hasOwnProperty(field) ) {
103+
continue;
107104
}
108-
$(this).html(elemText);
109-
$(".result-highlight", $(this)).toggleClass("result-highlight-colored");
110-
});
111-
$(".result-highlight-control").show();
105+
var positions = ranges[field];
106+
var fieldNameHash = CryptoJS.MD5(field);
107+
$(".result-td-" + fieldNameHash, $(this)).each(function(){
108+
var elemText = $(this).text();
109+
for (var idx = positions.length - 1; idx >= 0; idx--) {
110+
var range = positions[idx];
111+
elemText = elemText.gl2_splice(range.start + range.length, "</span>");
112+
elemText = elemText.gl2_splice(range.start, '<span class="result-highlight">');
113+
}
114+
$(this).html(elemText);
115+
$(".result-highlight", $(this)).toggleClass("result-highlight-colored");
116+
});
117+
$(".result-highlight-control").show();
118+
}
112119
}
113120
});
114121

0 commit comments

Comments
 (0)