fix #2356 check if pattern exists

This commit is contained in:
Shinsuke Sugaya 2020-01-05 15:41:19 +09:00
parent ba0ff8b075
commit ee61a2b778

View file

@ -216,18 +216,19 @@ public class ViewHelper {
if (!fessConfig.isResponseHighlightContentTitleEnabled()) {
return value;
}
return getQuerySet().map(
querySet -> {
final Matcher matcher =
Pattern.compile(querySet.stream().map(LaFunctions::h).map(Pattern::quote).collect(Collectors.joining("|")),
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(value);
final StringBuffer buf = new StringBuffer(value.length() + 100);
while (matcher.find()) {
matcher.appendReplacement(buf, highlightTagPre + matcher.group(0) + highlightTagPost);
}
matcher.appendTail(buf);
return buf.toString();
}).orElse(value);
return getQuerySet().map(querySet -> {
final String pattern = querySet.stream().map(LaFunctions::h).map(Pattern::quote).collect(Collectors.joining("|"));
if (StringUtil.isBlank(pattern)) {
return null;
}
final Matcher matcher = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(value);
final StringBuffer buf = new StringBuffer(value.length() + 100);
while (matcher.find()) {
matcher.appendReplacement(buf, highlightTagPre + matcher.group(0) + highlightTagPost);
}
matcher.appendTail(buf);
return buf.toString();
}).orElse(value);
}
protected OptionalThing<Set<String>> getQuerySet() {