فهرست منبع

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

Shinsuke Sugaya 7 سال پیش
والد
کامیت
cd906cb3cb

+ 3 - 3
src/main/java/org/codelibs/fess/crawler/transformer/AbstractFessFileTransformer.java

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

+ 10 - 1
src/main/java/org/codelibs/fess/crawler/transformer/FessTransformer.java

@@ -104,7 +104,7 @@ public interface FessTransformer {
             } catch (final Exception e) {}
             } 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) {
     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();
         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) {
     public default String getFileName(final String url, final String encoding) {
         if (StringUtil.isBlank(url)) {
         if (StringUtil.isBlank(url)) {
             return StringUtil.EMPTY;
             return StringUtil.EMPTY;

+ 14 - 3
src/main/java/org/codelibs/fess/helper/ViewHelper.java

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

+ 54 - 0
src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java

@@ -429,6 +429,12 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. site_path */
     /** The key of the configuration. e.g. site_path */
     String RESPONSE_FIELD_site_path = "response.field.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 */
     /** The key of the configuration. e.g. fess.search */
     String INDEX_DOCUMENT_SEARCH_INDEX = "index.document.search.index";
     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();
     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>
      * Get the value for the key 'index.document.search.index'. <br>
      * The value is, e.g. fess.search <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);
             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() {
         public String getIndexDocumentSearchIndex() {
             return get(FessConfig.INDEX_DOCUMENT_SEARCH_INDEX);
             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_content_description, "content_description");
             defaultMap.put(FessConfig.RESPONSE_FIELD_url_link, "url_link");
             defaultMap.put(FessConfig.RESPONSE_FIELD_url_link, "url_link");
             defaultMap.put(FessConfig.RESPONSE_FIELD_site_path, "site_path");
             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_SEARCH_INDEX, "fess.search");
             defaultMap.put(FessConfig.INDEX_DOCUMENT_UPDATE_INDEX, "fess.update");
             defaultMap.put(FessConfig.INDEX_DOCUMENT_UPDATE_INDEX, "fess.update");
             defaultMap.put(FessConfig.INDEX_DOCUMENT_TYPE, "doc");
             defaultMap.put(FessConfig.INDEX_DOCUMENT_TYPE, "doc");

+ 2 - 0
src/main/resources/fess_config.properties

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