fix #1364 add response.max.title.length and response.max.site.path.length

This commit is contained in:
Shinsuke Sugaya 2017-11-29 23:36:24 +09:00
parent 2dce710096
commit cd906cb3cb
5 changed files with 83 additions and 7 deletions

View file

@ -472,15 +472,15 @@ public abstract class AbstractFessFileTransformer extends AbstractTransformer im
if (url.startsWith("file:////")) {
final String value = decodeUrlAsName(url.substring(9), true);
return StringUtils.abbreviate("\\\\" + value.replace('/', '\\'), getMaxSiteLength());
return abbreviateSite("\\\\" + value.replace('/', '\\'));
} else if (url.startsWith("file:")) {
final String value = decodeUrlAsName(url.substring(5), true);
if (value.length() > 2 && value.charAt(2) == ':') {
// Windows
return StringUtils.abbreviate(value.substring(1).replace('/', '\\'), getMaxSiteLength());
return abbreviateSite(value.substring(1).replace('/', '\\'));
} else {
// Unix
return StringUtils.abbreviate(value, getMaxSiteLength());
return abbreviateSite(value);
}
}

View file

@ -104,7 +104,7 @@ public interface FessTransformer {
} catch (final Exception e) {}
}
return StringUtils.abbreviate(url, getMaxSiteLength());
return abbreviateSite(url);
}
public default void putResultDataBody(final Map<String, Object> dataMap, final String key, final Object value) {
@ -180,6 +180,15 @@ public interface FessTransformer {
return getFessConfig().getCrawlerDocumentMaxSiteLengthAsInteger();
}
public default String abbreviateSite(final String value) {
final int maxSiteLength = getMaxSiteLength();
if (maxSiteLength > -1) {
return StringUtils.abbreviate(value, maxSiteLength);
} else {
return value;
}
}
public default String getFileName(final String url, final String encoding) {
if (StringUtil.isBlank(url)) {
return StringUtil.EMPTY;

View file

@ -102,8 +102,10 @@ public class ViewHelper {
@Resource
protected UserAgentHelper userAgentHelper;
@Deprecated
public int titleLength = 50;
@Deprecated
public int sitePathLength = 50;
public boolean encodeUrlLink = false;
@ -147,7 +149,6 @@ public class ViewHelper {
}
public String getContentTitle(final Map<String, Object> document) {
final int size = titleLength;
final FessConfig fessConfig = ComponentUtil.getFessConfig();
String title = DocumentUtil.getValue(document, fessConfig.getIndexFieldTitle(), String.class);
if (StringUtil.isBlank(title)) {
@ -156,7 +157,12 @@ public class ViewHelper {
title = DocumentUtil.getValue(document, fessConfig.getIndexFieldUrl(), String.class);
}
}
return StringUtils.abbreviate(title, size);
final int size = fessConfig.getResponseMaxTitleLengthAsInteger();
if (size > -1) {
return StringUtils.abbreviate(title, size);
} else {
return title;
}
}
public String getContentDescription(final Map<String, Object> document) {
@ -487,7 +493,12 @@ public class ViewHelper {
} else {
returnUrl = url.replaceFirst("^[a-zA-Z0-9]*:/+", "");
}
return StringUtils.abbreviate(returnUrl, sitePathLength);
final int size = fessConfig.getResponseMaxSitePathLengthAsInteger();
if (size > -1) {
return StringUtils.abbreviate(returnUrl, size);
} else {
return returnUrl;
}
}
return null;
}

View file

@ -429,6 +429,12 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. site_path */
String RESPONSE_FIELD_site_path = "response.field.site_path";
/** The key of the configuration. e.g. 50 */
String RESPONSE_MAX_TITLE_LENGTH = "response.max.title.length";
/** The key of the configuration. e.g. 50 */
String RESPONSE_MAX_SITE_PATH_LENGTH = "response.max.site.path.length";
/** The key of the configuration. e.g. fess.search */
String INDEX_DOCUMENT_SEARCH_INDEX = "index.document.search.index";
@ -2527,6 +2533,36 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
String getResponseFieldSitePath();
/**
* Get the value for the key 'response.max.title.length'. <br>
* The value is, e.g. 50 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getResponseMaxTitleLength();
/**
* Get the value for the key 'response.max.title.length' as {@link Integer}. <br>
* The value is, e.g. 50 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
* @throws NumberFormatException When the property is not integer.
*/
Integer getResponseMaxTitleLengthAsInteger();
/**
* Get the value for the key 'response.max.site.path.length'. <br>
* The value is, e.g. 50 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getResponseMaxSitePathLength();
/**
* Get the value for the key 'response.max.site.path.length' as {@link Integer}. <br>
* The value is, e.g. 50 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
* @throws NumberFormatException When the property is not integer.
*/
Integer getResponseMaxSitePathLengthAsInteger();
/**
* Get the value for the key 'index.document.search.index'. <br>
* The value is, e.g. fess.search <br>
@ -6047,6 +6083,22 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
return get(FessConfig.RESPONSE_FIELD_site_path);
}
public String getResponseMaxTitleLength() {
return get(FessConfig.RESPONSE_MAX_TITLE_LENGTH);
}
public Integer getResponseMaxTitleLengthAsInteger() {
return getAsInteger(FessConfig.RESPONSE_MAX_TITLE_LENGTH);
}
public String getResponseMaxSitePathLength() {
return get(FessConfig.RESPONSE_MAX_SITE_PATH_LENGTH);
}
public Integer getResponseMaxSitePathLengthAsInteger() {
return getAsInteger(FessConfig.RESPONSE_MAX_SITE_PATH_LENGTH);
}
public String getIndexDocumentSearchIndex() {
return get(FessConfig.INDEX_DOCUMENT_SEARCH_INDEX);
}
@ -7707,6 +7759,8 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
defaultMap.put(FessConfig.RESPONSE_FIELD_content_description, "content_description");
defaultMap.put(FessConfig.RESPONSE_FIELD_url_link, "url_link");
defaultMap.put(FessConfig.RESPONSE_FIELD_site_path, "site_path");
defaultMap.put(FessConfig.RESPONSE_MAX_TITLE_LENGTH, "50");
defaultMap.put(FessConfig.RESPONSE_MAX_SITE_PATH_LENGTH, "50");
defaultMap.put(FessConfig.INDEX_DOCUMENT_SEARCH_INDEX, "fess.search");
defaultMap.put(FessConfig.INDEX_DOCUMENT_UPDATE_INDEX, "fess.update");
defaultMap.put(FessConfig.INDEX_DOCUMENT_TYPE, "doc");

View file

@ -210,6 +210,8 @@ response.field.content_title=content_title
response.field.content_description=content_description
response.field.url_link=url_link
response.field.site_path=site_path
response.max.title.length=50
response.max.site.path.length=50
# document index
index.document.search.index=fess.search