diff --git a/src/main/java/org/codelibs/fess/es/client/FessEsClient.java b/src/main/java/org/codelibs/fess/es/client/FessEsClient.java
index 42f4b33c0..349891973 100644
--- a/src/main/java/org/codelibs/fess/es/client/FessEsClient.java
+++ b/src/main/java/org/codelibs/fess/es/client/FessEsClient.java
@@ -49,6 +49,7 @@ import org.codelibs.fess.entity.GeoInfo;
import org.codelibs.fess.entity.PingResponse;
import org.codelibs.fess.entity.QueryContext;
import org.codelibs.fess.exception.FessSystemException;
+import org.codelibs.fess.exception.InvalidQueryException;
import org.codelibs.fess.exception.ResultOffsetExceededException;
import org.codelibs.fess.exception.SearchQueryException;
import org.codelibs.fess.helper.QueryHelper;
@@ -121,6 +122,7 @@ import org.elasticsearch.action.search.ClearScrollResponse;
import org.elasticsearch.action.search.MultiSearchRequest;
import org.elasticsearch.action.search.MultiSearchRequestBuilder;
import org.elasticsearch.action.search.MultiSearchResponse;
+import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
@@ -162,6 +164,7 @@ import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuil
import org.elasticsearch.search.aggregations.bucket.terms.Terms.Order;
import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
import org.elasticsearch.threadpool.ThreadPool;
+import org.lastaflute.core.message.UserMessages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -535,7 +538,12 @@ public class FessEsClient implements Client {
}
}
- searchResponse = searchRequestBuilder.execute().actionGet();
+ try {
+ searchResponse = searchRequestBuilder.execute().actionGet();
+ } catch (SearchPhaseExecutionException e) {
+ throw new InvalidQueryException(messages -> messages.addErrorsInvalidQueryParseError(UserMessages.GLOBAL_PROPERTY_KEY),
+ "Invalid query: " + searchRequestBuilder, e);
+ }
}
final long execTime = System.currentTimeMillis() - startTime;
diff --git a/src/main/java/org/codelibs/fess/helper/QueryHelper.java b/src/main/java/org/codelibs/fess/helper/QueryHelper.java
index 4969b3cfb..271cea2b8 100644
--- a/src/main/java/org/codelibs/fess/helper/QueryHelper.java
+++ b/src/main/java/org/codelibs/fess/helper/QueryHelper.java
@@ -395,7 +395,9 @@ public class QueryHelper implements Serializable {
protected QueryBuilder convertTermQuery(final QueryContext context, final TermQuery termQuery) {
final String field = termQuery.getTerm().field();
final String text = termQuery.getTerm().text();
- if (Constants.DEFAULT_FIELD.equals(field)) {
+ if (fessConfig.getQueryReplaceTermWithPrefixQueryAsBoolean() && text.length() > 1 && text.endsWith("*")) {
+ return convertPrefixQuery(context, new PrefixQuery(new Term(field, text.substring(0, text.length() - 1))));
+ } else if (Constants.DEFAULT_FIELD.equals(field)) {
context.addFieldLog(field, text);
context.addHighlightedQuery(text);
return buildDefaultQueryBuilder((f, b) -> QueryBuilders.matchPhraseQuery(f, text).boost(b));
diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
index 2245adc98..e086ce522 100644
--- a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
+++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
@@ -302,6 +302,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. 1000 */
String QUERY_MAX_LENGTH = "query.max.length";
+ /** The key of the configuration. e.g. true */
+ String QUERY_REPLACE_TERM_WITH_PREFIX_QUERY = "query.replace.term.with.prefix.query";
+
/** The key of the configuration. e.g. 1.6 */
String QUERY_BOOST_TITLE = "query.boost.title";
@@ -1392,6 +1395,20 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
Integer getQueryMaxLengthAsInteger();
+ /**
+ * Get the value for the key 'query.replace.term.with.prefix.query'.
+ * The value is, e.g. true
+ * @return The value of found property. (NotNull: if not found, exception but basically no way)
+ */
+ String getQueryReplaceTermWithPrefixQuery();
+
+ /**
+ * Is the property for the key 'query.replace.term.with.prefix.query' true?
+ * The value is, e.g. true
+ * @return The determination, true or false. (if not found, exception but basically no way)
+ */
+ boolean isQueryReplaceTermWithPrefixQuery();
+
/**
* Get the value for the key 'query.boost.title'.
* The value is, e.g. 1.6
@@ -2734,6 +2751,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
return getAsInteger(FessConfig.QUERY_MAX_LENGTH);
}
+ public String getQueryReplaceTermWithPrefixQuery() {
+ return get(FessConfig.QUERY_REPLACE_TERM_WITH_PREFIX_QUERY);
+ }
+
+ public boolean isQueryReplaceTermWithPrefixQuery() {
+ return is(FessConfig.QUERY_REPLACE_TERM_WITH_PREFIX_QUERY);
+ }
+
public String getQueryBoostTitle() {
return get(FessConfig.QUERY_BOOST_TITLE);
}
diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java
index d9a757d17..f87d57800 100644
--- a/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java
+++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java
@@ -367,4 +367,11 @@ public interface FessProp {
public default String[] getSuggestPopularWordExcludesAsArray() {
return StreamUtil.of(getSuggestPopularWordExcludes().split("\n")).filter(s -> StringUtil.isNotBlank(s)).toArray(n -> new String[n]);
}
+
+ String getQueryReplaceTermWithPrefixQuery();
+
+ public default boolean getQueryReplaceTermWithPrefixQueryAsBoolean() {
+ return Boolean.valueOf(getQueryReplaceTermWithPrefixQuery());
+ }
+
}
diff --git a/src/main/resources/fess_config.properties b/src/main/resources/fess_config.properties
index 29084e3ce..1bfe56eda 100644
--- a/src/main/resources/fess_config.properties
+++ b/src/main/resources/fess_config.properties
@@ -149,6 +149,7 @@ index.document.type=doc
# query
query.max.length=1000
+query.replace.term.with.prefix.query=true
# boost
query.boost.title=1.6