浏览代码

fix #2512 add prefix_length and transpositions

Shinsuke Sugaya 4 年之前
父节点
当前提交
e2f69f864f

+ 6 - 1
src/main/java/org/codelibs/fess/helper/QueryHelper.java

@@ -687,12 +687,17 @@ public class QueryHelper {
     protected QueryBuilder buildDefaultTermQueryBuilder(final float boost, final String text) {
     protected QueryBuilder buildDefaultTermQueryBuilder(final float boost, final String text) {
         final BoolQueryBuilder boolQuery = buildDefaultQueryBuilder((f, b) -> buildMatchPhraseQuery(f, text).boost(b * boost));
         final BoolQueryBuilder boolQuery = buildDefaultQueryBuilder((f, b) -> buildMatchPhraseQuery(f, text).boost(b * boost));
         final FessConfig fessConfig = ComponentUtil.getFessConfig();
         final FessConfig fessConfig = ComponentUtil.getFessConfig();
-        if (text.length() >= fessConfig.getQueryBoostFuzzyMinLengthAsInteger()) {
+        final Integer fuzzyMinLength = fessConfig.getQueryBoostFuzzyMinLengthAsInteger();
+        if (fuzzyMinLength >= 0 && text.length() >= fuzzyMinLength) {
             boolQuery.should(QueryBuilders.fuzzyQuery(fessConfig.getIndexFieldTitle(), text)
             boolQuery.should(QueryBuilders.fuzzyQuery(fessConfig.getIndexFieldTitle(), text)
                     .boost(fessConfig.getQueryBoostFuzzyTitleAsDecimal().floatValue())
                     .boost(fessConfig.getQueryBoostFuzzyTitleAsDecimal().floatValue())
+                    .prefixLength(fessConfig.getQueryBoostFuzzyTitlePrefixLengthAsInteger())
+                    .transpositions(Constants.TRUE.equalsIgnoreCase(fessConfig.getQueryBoostFuzzyTitleTranspositions()))
                     .fuzziness(Fuzziness.build(fessConfig.getQueryBoostFuzzyTitleFuzziness()))
                     .fuzziness(Fuzziness.build(fessConfig.getQueryBoostFuzzyTitleFuzziness()))
                     .maxExpansions(fessConfig.getQueryBoostFuzzyTitleExpansionsAsInteger()));
                     .maxExpansions(fessConfig.getQueryBoostFuzzyTitleExpansionsAsInteger()));
             boolQuery.should(QueryBuilders.fuzzyQuery(fessConfig.getIndexFieldContent(), text)
             boolQuery.should(QueryBuilders.fuzzyQuery(fessConfig.getIndexFieldContent(), text)
+                    .prefixLength(fessConfig.getQueryBoostFuzzyContentPrefixLengthAsInteger())
+                    .transpositions(Constants.TRUE.equalsIgnoreCase(fessConfig.getQueryBoostFuzzyContentTranspositions()))
                     .boost(fessConfig.getQueryBoostFuzzyContentAsDecimal().floatValue())
                     .boost(fessConfig.getQueryBoostFuzzyContentAsDecimal().floatValue())
                     .fuzziness(Fuzziness.build(fessConfig.getQueryBoostFuzzyContentFuzziness()))
                     .fuzziness(Fuzziness.build(fessConfig.getQueryBoostFuzzyContentFuzziness()))
                     .maxExpansions(fessConfig.getQueryBoostFuzzyContentExpansionsAsInteger()));
                     .maxExpansions(fessConfig.getQueryBoostFuzzyContentExpansionsAsInteger()));

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

@@ -959,6 +959,12 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. 10 */
     /** The key of the configuration. e.g. 10 */
     String QUERY_BOOST_FUZZY_TITLE_EXPANSIONS = "query.boost.fuzzy.title.expansions";
     String QUERY_BOOST_FUZZY_TITLE_EXPANSIONS = "query.boost.fuzzy.title.expansions";
 
 
+    /** The key of the configuration. e.g. 0 */
+    String QUERY_BOOST_FUZZY_TITLE_prefix_length = "query.boost.fuzzy.title.prefix_length";
+
+    /** The key of the configuration. e.g. true */
+    String QUERY_BOOST_FUZZY_TITLE_TRANSPOSITIONS = "query.boost.fuzzy.title.transpositions";
+
     /** The key of the configuration. e.g. 0.005 */
     /** The key of the configuration. e.g. 0.005 */
     String QUERY_BOOST_FUZZY_CONTENT = "query.boost.fuzzy.content";
     String QUERY_BOOST_FUZZY_CONTENT = "query.boost.fuzzy.content";
 
 
@@ -968,6 +974,12 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. 10 */
     /** The key of the configuration. e.g. 10 */
     String QUERY_BOOST_FUZZY_CONTENT_EXPANSIONS = "query.boost.fuzzy.content.expansions";
     String QUERY_BOOST_FUZZY_CONTENT_EXPANSIONS = "query.boost.fuzzy.content.expansions";
 
 
+    /** The key of the configuration. e.g. 0 */
+    String QUERY_BOOST_FUZZY_CONTENT_prefix_length = "query.boost.fuzzy.content.prefix_length";
+
+    /** The key of the configuration. e.g. true */
+    String QUERY_BOOST_FUZZY_CONTENT_TRANSPOSITIONS = "query.boost.fuzzy.content.transpositions";
+
     /** The key of the configuration. e.g. label */
     /** The key of the configuration. e.g. label */
     String QUERY_FACET_FIELDS = "query.facet.fields";
     String QUERY_FACET_FIELDS = "query.facet.fields";
 
 
@@ -4443,6 +4455,35 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
      */
      */
     Integer getQueryBoostFuzzyTitleExpansionsAsInteger();
     Integer getQueryBoostFuzzyTitleExpansionsAsInteger();
 
 
+    /**
+     * Get the value for the key 'query.boost.fuzzy.title.prefix_length'. <br>
+     * The value is, e.g. 0 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getQueryBoostFuzzyTitlePrefixLength();
+
+    /**
+     * Get the value for the key 'query.boost.fuzzy.title.prefix_length' as {@link Integer}. <br>
+     * The value is, e.g. 0 <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 getQueryBoostFuzzyTitlePrefixLengthAsInteger();
+
+    /**
+     * Get the value for the key 'query.boost.fuzzy.title.transpositions'. <br>
+     * The value is, e.g. true <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getQueryBoostFuzzyTitleTranspositions();
+
+    /**
+     * Is the property for the key 'query.boost.fuzzy.title.transpositions' true? <br>
+     * The value is, e.g. true <br>
+     * @return The determination, true or false. (if not found, exception but basically no way)
+     */
+    boolean isQueryBoostFuzzyTitleTranspositions();
+
     /**
     /**
      * Get the value for the key 'query.boost.fuzzy.content'. <br>
      * Get the value for the key 'query.boost.fuzzy.content'. <br>
      * The value is, e.g. 0.005 <br>
      * The value is, e.g. 0.005 <br>
@@ -4480,6 +4521,35 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
      */
      */
     Integer getQueryBoostFuzzyContentExpansionsAsInteger();
     Integer getQueryBoostFuzzyContentExpansionsAsInteger();
 
 
+    /**
+     * Get the value for the key 'query.boost.fuzzy.content.prefix_length'. <br>
+     * The value is, e.g. 0 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getQueryBoostFuzzyContentPrefixLength();
+
+    /**
+     * Get the value for the key 'query.boost.fuzzy.content.prefix_length' as {@link Integer}. <br>
+     * The value is, e.g. 0 <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 getQueryBoostFuzzyContentPrefixLengthAsInteger();
+
+    /**
+     * Get the value for the key 'query.boost.fuzzy.content.transpositions'. <br>
+     * The value is, e.g. true <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getQueryBoostFuzzyContentTranspositions();
+
+    /**
+     * Is the property for the key 'query.boost.fuzzy.content.transpositions' true? <br>
+     * The value is, e.g. true <br>
+     * @return The determination, true or false. (if not found, exception but basically no way)
+     */
+    boolean isQueryBoostFuzzyContentTranspositions();
+
     /**
     /**
      * Get the value for the key 'query.facet.fields'. <br>
      * Get the value for the key 'query.facet.fields'. <br>
      * The value is, e.g. label <br>
      * The value is, e.g. label <br>
@@ -8208,6 +8278,22 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             return getAsInteger(FessConfig.QUERY_BOOST_FUZZY_TITLE_EXPANSIONS);
             return getAsInteger(FessConfig.QUERY_BOOST_FUZZY_TITLE_EXPANSIONS);
         }
         }
 
 
+        public String getQueryBoostFuzzyTitlePrefixLength() {
+            return get(FessConfig.QUERY_BOOST_FUZZY_TITLE_prefix_length);
+        }
+
+        public Integer getQueryBoostFuzzyTitlePrefixLengthAsInteger() {
+            return getAsInteger(FessConfig.QUERY_BOOST_FUZZY_TITLE_prefix_length);
+        }
+
+        public String getQueryBoostFuzzyTitleTranspositions() {
+            return get(FessConfig.QUERY_BOOST_FUZZY_TITLE_TRANSPOSITIONS);
+        }
+
+        public boolean isQueryBoostFuzzyTitleTranspositions() {
+            return is(FessConfig.QUERY_BOOST_FUZZY_TITLE_TRANSPOSITIONS);
+        }
+
         public String getQueryBoostFuzzyContent() {
         public String getQueryBoostFuzzyContent() {
             return get(FessConfig.QUERY_BOOST_FUZZY_CONTENT);
             return get(FessConfig.QUERY_BOOST_FUZZY_CONTENT);
         }
         }
@@ -8228,6 +8314,22 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             return getAsInteger(FessConfig.QUERY_BOOST_FUZZY_CONTENT_EXPANSIONS);
             return getAsInteger(FessConfig.QUERY_BOOST_FUZZY_CONTENT_EXPANSIONS);
         }
         }
 
 
+        public String getQueryBoostFuzzyContentPrefixLength() {
+            return get(FessConfig.QUERY_BOOST_FUZZY_CONTENT_prefix_length);
+        }
+
+        public Integer getQueryBoostFuzzyContentPrefixLengthAsInteger() {
+            return getAsInteger(FessConfig.QUERY_BOOST_FUZZY_CONTENT_prefix_length);
+        }
+
+        public String getQueryBoostFuzzyContentTranspositions() {
+            return get(FessConfig.QUERY_BOOST_FUZZY_CONTENT_TRANSPOSITIONS);
+        }
+
+        public boolean isQueryBoostFuzzyContentTranspositions() {
+            return is(FessConfig.QUERY_BOOST_FUZZY_CONTENT_TRANSPOSITIONS);
+        }
+
         public String getQueryFacetFields() {
         public String getQueryFacetFields() {
             return get(FessConfig.QUERY_FACET_FIELDS);
             return get(FessConfig.QUERY_FACET_FIELDS);
         }
         }
@@ -9740,9 +9842,13 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_TITLE, "0.01");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_TITLE, "0.01");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_TITLE_FUZZINESS, "AUTO");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_TITLE_FUZZINESS, "AUTO");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_TITLE_EXPANSIONS, "10");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_TITLE_EXPANSIONS, "10");
+            defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_TITLE_prefix_length, "0");
+            defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_TITLE_TRANSPOSITIONS, "true");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_CONTENT, "0.005");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_CONTENT, "0.005");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_CONTENT_FUZZINESS, "AUTO");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_CONTENT_FUZZINESS, "AUTO");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_CONTENT_EXPANSIONS, "10");
             defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_CONTENT_EXPANSIONS, "10");
+            defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_CONTENT_prefix_length, "0");
+            defaultMap.put(FessConfig.QUERY_BOOST_FUZZY_CONTENT_TRANSPOSITIONS, "true");
             defaultMap.put(FessConfig.QUERY_FACET_FIELDS, "label");
             defaultMap.put(FessConfig.QUERY_FACET_FIELDS, "label");
             defaultMap.put(FessConfig.QUERY_FACET_FIELDS_SIZE, "100");
             defaultMap.put(FessConfig.QUERY_FACET_FIELDS_SIZE, "100");
             defaultMap.put(FessConfig.QUERY_FACET_FIELDS_min_doc_count, "1");
             defaultMap.put(FessConfig.QUERY_FACET_FIELDS_min_doc_count, "1");

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

@@ -517,9 +517,13 @@ query.boost.fuzzy.min.length=4
 query.boost.fuzzy.title=0.01
 query.boost.fuzzy.title=0.01
 query.boost.fuzzy.title.fuzziness=AUTO
 query.boost.fuzzy.title.fuzziness=AUTO
 query.boost.fuzzy.title.expansions=10
 query.boost.fuzzy.title.expansions=10
+query.boost.fuzzy.title.prefix_length=0
+query.boost.fuzzy.title.transpositions=true
 query.boost.fuzzy.content=0.005
 query.boost.fuzzy.content=0.005
 query.boost.fuzzy.content.fuzziness=AUTO
 query.boost.fuzzy.content.fuzziness=AUTO
 query.boost.fuzzy.content.expansions=10
 query.boost.fuzzy.content.expansions=10
+query.boost.fuzzy.content.prefix_length=0
+query.boost.fuzzy.content.transpositions=true
 
 
 # facet
 # facet
 query.facet.fields=label
 query.facet.fields=label