fix #1647 use queries for highlighting

This commit is contained in:
Shinsuke Sugaya 2018-05-15 06:32:47 +09:00
parent ce58769519
commit 39144fb83c
2 changed files with 20 additions and 17 deletions

View file

@ -218,7 +218,6 @@ public class QueryHelper {
}
if (highlightedFields == null) {
highlightedFields = fessConfig.getQueryAdditionalHighlightedFields( //
fessConfig.getIndexFieldTitle(), //
fessConfig.getIndexFieldContent());
}
if (searchFields == null) {

View file

@ -148,27 +148,31 @@ public class ViewHelper {
public String getContentTitle(final Map<String, Object> document) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final int size = fessConfig.getResponseMaxTitleLengthAsInteger();
String title =
DocumentUtil.getValue(document, ComponentUtil.getQueryHelper().getHighlightPrefix() + fessConfig.getIndexFieldTitle(),
String.class);
if (StringUtil.isBlank(title) || title.length() > size - 3) {
title = DocumentUtil.getValue(document, fessConfig.getIndexFieldTitle(), String.class);
String title = DocumentUtil.getValue(document, fessConfig.getIndexFieldTitle(), String.class);
if (StringUtil.isBlank(title)) {
title = DocumentUtil.getValue(document, fessConfig.getIndexFieldFilename(), String.class);
if (StringUtil.isBlank(title)) {
title = DocumentUtil.getValue(document, fessConfig.getIndexFieldFilename(), String.class);
if (StringUtil.isBlank(title)) {
title = DocumentUtil.getValue(document, fessConfig.getIndexFieldUrl(), String.class);
}
title = DocumentUtil.getValue(document, fessConfig.getIndexFieldUrl(), String.class);
}
title = LaFunctions.h(title);
} else {
title = escapeHighlight(title).replaceAll("\\.\\.\\.$", StringUtil.EMPTY);
}
final int size = fessConfig.getResponseMaxTitleLengthAsInteger();
if (size > -1) {
return StringUtils.abbreviate(title, size);
} else {
return title;
title = StringUtils.abbreviate(title, size);
}
final String value = LaFunctions.h(title);
return LaRequestUtil.getOptionalRequest().map(req -> {
@SuppressWarnings("unchecked")
final Set<String> querySet = (Set<String>) req.getAttribute(Constants.HIGHLIGHT_QUERIES);
if (querySet != null) {
String t = value;
for (final String query : querySet) {
final String target = LaFunctions.h(query);
t = t.replace(target, highlightTagPre + target + highlightTagPost);
}
return t;
}
return value;
}).orElse(value);
}
public String getContentDescription(final Map<String, Object> document) {