Skip to content

Commit

Permalink
fix #2512 add prefix_length and transpositions
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Dec 30, 2020
1 parent 144de12 commit e2f69f8
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/org/codelibs/fess/helper/QueryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,17 @@ protected boolean isSearchField(final String field) {
protected QueryBuilder buildDefaultTermQueryBuilder(final float boost, final String text) {
final BoolQueryBuilder boolQuery = buildDefaultQueryBuilder((f, b) -> buildMatchPhraseQuery(f, text).boost(b * boost));
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)
.boost(fessConfig.getQueryBoostFuzzyTitleAsDecimal().floatValue())
.prefixLength(fessConfig.getQueryBoostFuzzyTitlePrefixLengthAsInteger())
.transpositions(Constants.TRUE.equalsIgnoreCase(fessConfig.getQueryBoostFuzzyTitleTranspositions()))
.fuzziness(Fuzziness.build(fessConfig.getQueryBoostFuzzyTitleFuzziness()))
.maxExpansions(fessConfig.getQueryBoostFuzzyTitleExpansionsAsInteger()));
boolQuery.should(QueryBuilders.fuzzyQuery(fessConfig.getIndexFieldContent(), text)
.prefixLength(fessConfig.getQueryBoostFuzzyContentPrefixLengthAsInteger())
.transpositions(Constants.TRUE.equalsIgnoreCase(fessConfig.getQueryBoostFuzzyContentTranspositions()))
.boost(fessConfig.getQueryBoostFuzzyContentAsDecimal().floatValue())
.fuzziness(Fuzziness.build(fessConfig.getQueryBoostFuzzyContentFuzziness()))
.maxExpansions(fessConfig.getQueryBoostFuzzyContentExpansionsAsInteger()));
Expand Down
106 changes: 106 additions & 0 deletions src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,12 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. 10 */
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 */
String QUERY_BOOST_FUZZY_CONTENT = "query.boost.fuzzy.content";

Expand All @@ -968,6 +974,12 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. 10 */
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 */
String QUERY_FACET_FIELDS = "query.facet.fields";

Expand Down Expand Up @@ -4443,6 +4455,35 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
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>
* The value is, e.g. 0.005 <br>
Expand Down Expand Up @@ -4480,6 +4521,35 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
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>
* The value is, e.g. label <br>
Expand Down Expand Up @@ -8208,6 +8278,22 @@ public Integer getQueryBoostFuzzyTitleExpansionsAsInteger() {
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() {
return get(FessConfig.QUERY_BOOST_FUZZY_CONTENT);
}
Expand All @@ -8228,6 +8314,22 @@ public Integer getQueryBoostFuzzyContentExpansionsAsInteger() {
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() {
return get(FessConfig.QUERY_FACET_FIELDS);
}
Expand Down Expand Up @@ -9740,9 +9842,13 @@ protected java.util.Map<String, String> prepareGeneratedDefaultMap() {
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_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_FUZZINESS, "AUTO");
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_SIZE, "100");
defaultMap.put(FessConfig.QUERY_FACET_FIELDS_min_doc_count, "1");
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/fess_config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,13 @@ query.boost.fuzzy.min.length=4
query.boost.fuzzy.title=0.01
query.boost.fuzzy.title.fuzziness=AUTO
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.fuzziness=AUTO
query.boost.fuzzy.content.expansions=10
query.boost.fuzzy.content.prefix_length=0
query.boost.fuzzy.content.transpositions=true

# facet
query.facet.fields=label
Expand Down

0 comments on commit e2f69f8

Please sign in to comment.