Browse Source

fix #1189 add query.timeout

Shinsuke Sugaya 8 years ago
parent
commit
f37e8fd9e8

+ 4 - 5
src/main/java/org/codelibs/fess/es/client/FessEsClient.java

@@ -683,11 +683,10 @@ public class FessEsClient implements Client {
         final SearchRequestBuilder searchRequestBuilder = client.prepareSearch(index).setTypes(type);
         final SearchRequestBuilder searchRequestBuilder = client.prepareSearch(index).setTypes(type);
         if (condition.build(searchRequestBuilder)) {
         if (condition.build(searchRequestBuilder)) {
 
 
-            if (ComponentUtil.hasQueryHelper()) {
-                final QueryHelper queryHelper = ComponentUtil.getQueryHelper();
-                if (queryHelper.getTimeAllowed() >= 0) {
-                    searchRequestBuilder.setTimeout(TimeValue.timeValueMillis(queryHelper.getTimeAllowed()));
-                }
+            final FessConfig fessConfig = ComponentUtil.getFessConfig();
+            final long queryTimeout = fessConfig.getQueryTimeoutAsInteger().longValue();
+            if (queryTimeout >= 0) {
+                searchRequestBuilder.setTimeout(TimeValue.timeValueMillis(queryTimeout));
             }
             }
 
 
             try {
             try {

+ 0 - 16
src/main/java/org/codelibs/fess/helper/QueryHelper.java

@@ -115,8 +115,6 @@ public class QueryHelper {
 
 
     protected boolean lowercaseWildcard = true;
     protected boolean lowercaseWildcard = true;
 
 
-    protected long timeAllowed = -1;
-
     protected SortBuilder<?>[] defaultSortBuilders;
     protected SortBuilder<?>[] defaultSortBuilders;
 
 
     protected String highlightPrefix = "hl_";
     protected String highlightPrefix = "hl_";
@@ -751,20 +749,6 @@ public class QueryHelper {
         this.additionalQuery = additionalQuery;
         this.additionalQuery = additionalQuery;
     }
     }
 
 
-    /**
-     * @return the timeAllowed
-     */
-    public long getTimeAllowed() {
-        return timeAllowed;
-    }
-
-    /**
-     * @param timeAllowed the timeAllowed to set
-     */
-    public void setTimeAllowed(final long timeAllowed) {
-        this.timeAllowed = timeAllowed;
-    }
-
     public void addDefaultSort(final String fieldName, final String order) {
     public void addDefaultSort(final String fieldName, final String order) {
         final List<SortBuilder<?>> list = new ArrayList<>();
         final List<SortBuilder<?>> list = new ArrayList<>();
         if (defaultSortBuilders != null) {
         if (defaultSortBuilders != null) {

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

@@ -474,6 +474,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. 1000 */
     /** The key of the configuration. e.g. 1000 */
     String QUERY_MAX_LENGTH = "query.max.length";
     String QUERY_MAX_LENGTH = "query.max.length";
 
 
+    /** The key of the configuration. e.g. 10000 */
+    String QUERY_TIMEOUT = "query.timeout";
+
     /** The key of the configuration. e.g. location */
     /** The key of the configuration. e.g. location */
     String QUERY_GEO_FIELDS = "query.geo.fields";
     String QUERY_GEO_FIELDS = "query.geo.fields";
 
 
@@ -2626,6 +2629,21 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
      */
      */
     Integer getQueryMaxLengthAsInteger();
     Integer getQueryMaxLengthAsInteger();
 
 
+    /**
+     * Get the value for the key 'query.timeout'. <br>
+     * The value is, e.g. 10000 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getQueryTimeout();
+
+    /**
+     * Get the value for the key 'query.timeout' as {@link Integer}. <br>
+     * The value is, e.g. 10000 <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 getQueryTimeoutAsInteger();
+
     /**
     /**
      * Get the value for the key 'query.geo.fields'. <br>
      * Get the value for the key 'query.geo.fields'. <br>
      * The value is, e.g. location <br>
      * The value is, e.g. location <br>
@@ -5939,6 +5957,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             return getAsInteger(FessConfig.QUERY_MAX_LENGTH);
             return getAsInteger(FessConfig.QUERY_MAX_LENGTH);
         }
         }
 
 
+        public String getQueryTimeout() {
+            return get(FessConfig.QUERY_TIMEOUT);
+        }
+
+        public Integer getQueryTimeoutAsInteger() {
+            return getAsInteger(FessConfig.QUERY_TIMEOUT);
+        }
+
         public String getQueryGeoFields() {
         public String getQueryGeoFields() {
             return get(FessConfig.QUERY_GEO_FIELDS);
             return get(FessConfig.QUERY_GEO_FIELDS);
         }
         }

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

@@ -221,6 +221,7 @@ index.indices.timeout=1m
 
 
 # query
 # query
 query.max.length=1000
 query.max.length=1000
+query.timeout=10000
 query.geo.fields=location
 query.geo.fields=location
 query.browser.lang.parameter.name=browser_lang
 query.browser.lang.parameter.name=browser_lang
 query.replace.term.with.prefix.query=true
 query.replace.term.with.prefix.query=true