Skip to content

Commit

Permalink
fix #2502 update boost values
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Nov 28, 2020
1 parent b9086a2 commit c18f80a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 28 deletions.
26 changes: 14 additions & 12 deletions src/main/java/org/codelibs/fess/helper/QueryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -687,19 +687,21 @@ protected boolean isSearchField(final String field) {
protected QueryBuilder buildDefaultQueryBuilder(final DefaultQueryBuilderFunction builder) {
final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final QueryBuilder titleQuery =
builder.apply(fessConfig.getIndexFieldTitle(), fessConfig.getQueryBoostTitleAsDecimal().floatValue());
boolQuery.should(titleQuery);
final QueryBuilder contentQuery =
builder.apply(fessConfig.getIndexFieldContent(), fessConfig.getQueryBoostContentAsDecimal().floatValue());
boolQuery.should(contentQuery);
boolQuery.should(builder.apply(fessConfig.getIndexFieldTitle(), fessConfig.getQueryBoostTitleAsDecimal().floatValue()));
boolQuery.should(builder.apply(fessConfig.getIndexFieldContent(), fessConfig.getQueryBoostContentAsDecimal().floatValue()));
final float importantContentBoost = fessConfig.getQueryBoostImportantContentAsDecimal().floatValue();
if (importantContentBoost >= 0.0f) {
boolQuery.should(builder.apply(fessConfig.getIndexFieldImportantContent(), importantContentBoost));
}
final float importantContantLangBoost = fessConfig.getQueryBoostImportantContentLangAsDecimal().floatValue();
getQueryLanguages().ifPresent(langs -> stream(langs).of(stream -> stream.forEach(lang -> {
final QueryBuilder titleLangQuery =
builder.apply(fessConfig.getIndexFieldTitle() + "_" + lang, fessConfig.getQueryBoostTitleLangAsDecimal().floatValue());
boolQuery.should(titleLangQuery);
final QueryBuilder contentLangQuery = builder.apply(fessConfig.getIndexFieldContent() + "_" + lang,
fessConfig.getQueryBoostContentLangAsDecimal().floatValue());
boolQuery.should(contentLangQuery);
boolQuery.should(
builder.apply(fessConfig.getIndexFieldTitle() + "_" + lang, fessConfig.getQueryBoostTitleLangAsDecimal().floatValue()));
boolQuery.should(builder.apply(fessConfig.getIndexFieldContent() + "_" + lang,
fessConfig.getQueryBoostContentLangAsDecimal().floatValue()));
if (importantContantLangBoost >= 0.0f) {
boolQuery.should(builder.apply(fessConfig.getIndexFieldImportantContent() + "_" + lang, importantContantLangBoost));
}
})));
additionalDefaultList.stream().forEach(f -> {
final QueryBuilder query = builder.apply(f.getFirst(), f.getSecond());
Expand Down
78 changes: 66 additions & 12 deletions src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -926,18 +926,24 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
String QUERY_LANGUAGE_MAPPING = "query.language.mapping";

/** The key of the configuration. e.g. 0.01 */
/** The key of the configuration. e.g. 0.5 */
String QUERY_BOOST_TITLE = "query.boost.title";

/** The key of the configuration. e.g. 1.0 */
String QUERY_BOOST_TITLE_LANG = "query.boost.title.lang";

/** The key of the configuration. e.g. 0.005 */
/** The key of the configuration. e.g. 0.05 */
String QUERY_BOOST_CONTENT = "query.boost.content";

/** The key of the configuration. e.g. 0.5 */
/** The key of the configuration. e.g. 0.1 */
String QUERY_BOOST_CONTENT_LANG = "query.boost.content.lang";

/** The key of the configuration. e.g. -1.0 */
String QUERY_BOOST_important_content = "query.boost.important_content";

/** The key of the configuration. e.g. -1.0 */
String QUERY_BOOST_important_content_LANG = "query.boost.important_content.lang";

/** The key of the configuration. e.g. label */
String QUERY_FACET_FIELDS = "query.facet.fields";

Expand Down Expand Up @@ -4261,15 +4267,15 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction

/**
* Get the value for the key 'query.boost.title'. <br>
* The value is, e.g. 0.01 <br>
* The value is, e.g. 0.5 <br>
* comment: boost
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getQueryBoostTitle();

/**
* Get the value for the key 'query.boost.title' as {@link java.math.BigDecimal}. <br>
* The value is, e.g. 0.01 <br>
* The value is, e.g. 0.5 <br>
* comment: boost
* @return The value of found property. (NotNull: if not found, exception but basically no way)
* @throws NumberFormatException When the property is not decimal.
Expand All @@ -4293,34 +4299,64 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction

/**
* Get the value for the key 'query.boost.content'. <br>
* The value is, e.g. 0.005 <br>
* The value is, e.g. 0.05 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getQueryBoostContent();

/**
* Get the value for the key 'query.boost.content' as {@link java.math.BigDecimal}. <br>
* The value is, e.g. 0.005 <br>
* The value is, e.g. 0.05 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
* @throws NumberFormatException When the property is not decimal.
*/
java.math.BigDecimal getQueryBoostContentAsDecimal();

/**
* Get the value for the key 'query.boost.content.lang'. <br>
* The value is, e.g. 0.5 <br>
* The value is, e.g. 0.1 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getQueryBoostContentLang();

/**
* Get the value for the key 'query.boost.content.lang' as {@link java.math.BigDecimal}. <br>
* The value is, e.g. 0.5 <br>
* The value is, e.g. 0.1 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
* @throws NumberFormatException When the property is not decimal.
*/
java.math.BigDecimal getQueryBoostContentLangAsDecimal();

/**
* Get the value for the key 'query.boost.important_content'. <br>
* The value is, e.g. -1.0 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getQueryBoostImportantContent();

/**
* Get the value for the key 'query.boost.important_content' as {@link java.math.BigDecimal}. <br>
* The value is, e.g. -1.0 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
* @throws NumberFormatException When the property is not decimal.
*/
java.math.BigDecimal getQueryBoostImportantContentAsDecimal();

/**
* Get the value for the key 'query.boost.important_content.lang'. <br>
* The value is, e.g. -1.0 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getQueryBoostImportantContentLang();

/**
* Get the value for the key 'query.boost.important_content.lang' as {@link java.math.BigDecimal}. <br>
* The value is, e.g. -1.0 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
* @throws NumberFormatException When the property is not decimal.
*/
java.math.BigDecimal getQueryBoostImportantContentLangAsDecimal();

/**
* Get the value for the key 'query.facet.fields'. <br>
* The value is, e.g. label <br>
Expand Down Expand Up @@ -7987,6 +8023,22 @@ public java.math.BigDecimal getQueryBoostContentLangAsDecimal() {
return getAsDecimal(FessConfig.QUERY_BOOST_CONTENT_LANG);
}

public String getQueryBoostImportantContent() {
return get(FessConfig.QUERY_BOOST_important_content);
}

public java.math.BigDecimal getQueryBoostImportantContentAsDecimal() {
return getAsDecimal(FessConfig.QUERY_BOOST_important_content);
}

public String getQueryBoostImportantContentLang() {
return get(FessConfig.QUERY_BOOST_important_content_LANG);
}

public java.math.BigDecimal getQueryBoostImportantContentLangAsDecimal() {
return getAsDecimal(FessConfig.QUERY_BOOST_important_content_LANG);
}

public String getQueryFacetFields() {
return get(FessConfig.QUERY_FACET_FIELDS);
}
Expand Down Expand Up @@ -9480,10 +9532,12 @@ protected java.util.Map<String, String> prepareGeneratedDefaultMap() {
defaultMap.put(FessConfig.QUERY_GSA_DEFAULT_PREFERENCE, "_query");
defaultMap.put(FessConfig.QUERY_LANGUAGE_MAPPING,
"ar=ar\nbg=bg\nbn=bn\nca=ca\nckb-iq=ckb-iq\nckb_IQ=ckb-iq\ncs=cs\nda=da\nde=de\nel=el\nen=en\nen-ie=en-ie\nen_IE=en-ie\nes=es\net=et\neu=eu\nfa=fa\nfi=fi\nfr=fr\ngl=gl\ngu=gu\nhe=he\nhi=hi\nhr=hr\nhu=hu\nhy=hy\nid=id\nit=it\nja=ja\nko=ko\nlt=lt\nlv=lv\nmk=mk\nml=ml\nnl=nl\nno=no\npa=pa\npl=pl\npt=pt\npt-br=pt-br\npt_BR=pt-br\nro=ro\nru=ru\nsi=si\nsq=sq\nsv=sv\nta=ta\nte=te\nth=th\ntl=tl\ntr=tr\nuk=uk\nur=ur\nvi=vi\nzh-cn=zh-cn\nzh_CN=zh-cn\nzh-tw=zh-tw\nzh_TW=zh-tw\nzh=zh\n");
defaultMap.put(FessConfig.QUERY_BOOST_TITLE, "0.01");
defaultMap.put(FessConfig.QUERY_BOOST_TITLE, "0.5");
defaultMap.put(FessConfig.QUERY_BOOST_TITLE_LANG, "1.0");
defaultMap.put(FessConfig.QUERY_BOOST_CONTENT, "0.005");
defaultMap.put(FessConfig.QUERY_BOOST_CONTENT_LANG, "0.5");
defaultMap.put(FessConfig.QUERY_BOOST_CONTENT, "0.05");
defaultMap.put(FessConfig.QUERY_BOOST_CONTENT_LANG, "0.1");
defaultMap.put(FessConfig.QUERY_BOOST_important_content, "-1.0");
defaultMap.put(FessConfig.QUERY_BOOST_important_content_LANG, "-1.0");
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
8 changes: 5 additions & 3 deletions src/main/resources/fess_config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,12 @@ zh_TW=zh-tw\n\
zh=zh\n\
# boost
query.boost.title=0.01
query.boost.title=0.5
query.boost.title.lang=1.0
query.boost.content=0.005
query.boost.content.lang=0.5
query.boost.content=0.05
query.boost.content.lang=0.1
query.boost.important_content=-1.0
query.boost.important_content.lang=-1.0

# facet
query.facet.fields=label
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/fess_indices/fess/doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@
},
"important_content": {
"type": "text",
"index": false
"analyzer": "standard_analyzer",
"search_analyzer": "standard_search_analyzer",
"term_vector": "with_positions_offsets"
},
"content": {
"type": "text",
Expand Down

0 comments on commit c18f80a

Please sign in to comment.