FIX: Post blurb incorrect when search contains a phrase match.

If the blurb generated is not around the search term, we will not be
able to highlight it on the client side.
This commit is contained in:
Guo Xiang Tan
2019-03-26 17:01:19 +08:00
parent 1799820256
commit dae0bb4c67
5 changed files with 48 additions and 11 deletions

View File

@@ -0,0 +1 @@
export const PHRASE_MATCH_REGEXP_PATTERN = '<%= Search::PHRASE_MATCH_REGEXP_PATTERN %>';

View File

@@ -1,7 +1,13 @@
import { PHRASE_MATCH_REGEXP_PATTERN } from "discourse/lib/concerns/search-constants";
export default function($elem, term) {
if (!_.isEmpty(term)) {
// special case ignore "l" which is used for magic sorting
let words = _.reject(term.match(/"[^"]+"|[^\s]+/g), t => t === "l");
let words = _.reject(
term.match(new RegExp(`${PHRASE_MATCH_REGEXP_PATTERN}|[^\s]+`, "g")),
t => t === "l"
);
words = words.map(w => w.replace(/^"(.*)"$/, "$1"));
$elem.highlight(words, { className: "search-highlight", wordsOnly: true });
}