Highlight the search term in search results
Sometimes we don't get the search term back in the highlights list, so make sure we add it.
This commit is contained in:
parent
e177263d9f
commit
6c99fab3dd
1 changed files with 11 additions and 8 deletions
|
@ -544,17 +544,20 @@ module.exports = React.createClass({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// postgres on synapse returns us precise details of the
|
// postgres on synapse returns us precise details of the strings
|
||||||
// strings which actually got matched for highlighting.
|
// which actually got matched for highlighting.
|
||||||
|
//
|
||||||
|
// In either case, we want to highlight the literal search term
|
||||||
|
// whether it was used by the search engine or not.
|
||||||
|
|
||||||
|
var highlights = results.highlights;
|
||||||
|
if (highlights.indexOf(self.state.searchTerm) < 0) {
|
||||||
|
highlights = highlights.concat(self.state.searchTerm);
|
||||||
|
}
|
||||||
|
|
||||||
// For overlapping highlights,
|
// For overlapping highlights,
|
||||||
// favour longer (more specific) terms first
|
// favour longer (more specific) terms first
|
||||||
var highlights = results.highlights.sort(function(a, b) { b.length - a.length });
|
highlights = highlights.sort(function(a, b) { b.length - a.length });
|
||||||
|
|
||||||
// sqlite doesn't give us any highlights, so just try to highlight the literal search term
|
|
||||||
if (highlights.length == 0) {
|
|
||||||
highlights = [ self.state.searchTerm ];
|
|
||||||
}
|
|
||||||
|
|
||||||
self.setState({
|
self.setState({
|
||||||
searchHighlights: highlights,
|
searchHighlights: highlights,
|
||||||
|
|
Loading…
Reference in a new issue