fix #393 : modify query languages
This commit is contained in:
parent
5a58ae5ffe
commit
a326a90366
8 changed files with 69 additions and 44 deletions
|
@ -372,4 +372,6 @@ public class Constants extends CoreLibConstants {
|
|||
public static final String MAPPING_TYPE_DOUBLE = "double";
|
||||
|
||||
public static final String PAGING_QUERY_LIST = "pagingQueryList";
|
||||
|
||||
public static final String REQUEST_LANGUAGES = "requestLanguages";
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import javax.annotation.Resource;
|
|||
import org.codelibs.core.beans.util.BeanUtil;
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.pager.WebConfigPager;
|
||||
import org.codelibs.fess.es.config.bsbhv.BsWebConfigBhv;
|
||||
import org.codelibs.fess.es.config.cbean.WebConfigCB;
|
||||
import org.codelibs.fess.es.config.exbhv.WebAuthenticationBhv;
|
||||
import org.codelibs.fess.es.config.exbhv.WebConfigBhv;
|
||||
|
|
|
@ -121,6 +121,7 @@ public class SearchAction extends FessSearchAction {
|
|||
updateSearchParams(form);
|
||||
buildLabelParams(form.fields);
|
||||
form.lang = searchService.getLanguages(request, form);
|
||||
request.setAttribute(Constants.REQUEST_LANGUAGES, form.lang);
|
||||
final WebRenderData renderData = new WebRenderData();
|
||||
searchService.search(request, form, renderData);
|
||||
return asHtml(path_SearchJsp).renderWith(data -> {
|
||||
|
|
|
@ -54,7 +54,6 @@ import org.codelibs.fess.entity.QueryContext;
|
|||
import org.codelibs.fess.exception.InvalidQueryException;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.util.StreamUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
import org.dbflute.optional.OptionalThing;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
|
@ -467,16 +466,19 @@ public class QueryHelper implements Serializable {
|
|||
final QueryBuilder contentQuery =
|
||||
builder.apply(fessConfig.getIndexFieldContent(), fessConfig.getQueryBoostContentAsDecimal().floatValue());
|
||||
boolQuery.should(contentQuery);
|
||||
getQueryLanguage().ifPresent(
|
||||
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);
|
||||
getQueryLanguages().ifPresent(
|
||||
langs -> {
|
||||
StreamUtil.of(langs).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);
|
||||
});
|
||||
});
|
||||
return boolQuery;
|
||||
}
|
||||
|
@ -485,12 +487,10 @@ public class QueryHelper implements Serializable {
|
|||
QueryBuilder apply(String field, float boost);
|
||||
}
|
||||
|
||||
protected OptionalThing<String> getQueryLanguage() {
|
||||
if (StringUtil.isNotBlank(fessConfig.getQueryDefaultLanguage())) {
|
||||
return OptionalEntity.of(fessConfig.getQueryDefaultLanguage());
|
||||
}
|
||||
return LaRequestUtil.getOptionalRequest().map(request -> fessConfig.getQueryLanguage(request.getLocale()));
|
||||
|
||||
protected OptionalThing<String[]> getQueryLanguages() {
|
||||
return LaRequestUtil.getOptionalRequest()
|
||||
.map(request -> fessConfig.getQueryLanguages(request.getLocales(),
|
||||
(String[]) request.getAttribute(Constants.REQUEST_LANGUAGES)));
|
||||
}
|
||||
|
||||
private boolean isSortField(final String field) {
|
||||
|
|
|
@ -318,7 +318,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
String QUERY_REPLACE_TERM_WITH_PREFIX_QUERY = "query.replace.term.with.prefix.query";
|
||||
|
||||
/** The key of the configuration. e.g. */
|
||||
String QUERY_DEFAULT_LANGUAGE = "query.default.language";
|
||||
String QUERY_DEFAULT_LANGUAGES = "query.default.languages";
|
||||
|
||||
/** The key of the configuration. e.g. ar=ar
|
||||
bg=bg
|
||||
|
@ -1578,19 +1578,19 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
boolean isQueryReplaceTermWithPrefixQuery();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'query.default.language'. <br>
|
||||
* Get the value for the key 'query.default.languages'. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
*/
|
||||
String getQueryDefaultLanguage();
|
||||
String getQueryDefaultLanguages();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'query.default.language' as {@link Integer}. <br>
|
||||
* Get the value for the key 'query.default.languages' as {@link Integer}. <br>
|
||||
* The value is, e.g. <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 getQueryDefaultLanguageAsInteger();
|
||||
Integer getQueryDefaultLanguagesAsInteger();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'query.language.mapping'. <br>
|
||||
|
@ -3202,12 +3202,12 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
return is(FessConfig.QUERY_REPLACE_TERM_WITH_PREFIX_QUERY);
|
||||
}
|
||||
|
||||
public String getQueryDefaultLanguage() {
|
||||
return get(FessConfig.QUERY_DEFAULT_LANGUAGE);
|
||||
public String getQueryDefaultLanguages() {
|
||||
return get(FessConfig.QUERY_DEFAULT_LANGUAGES);
|
||||
}
|
||||
|
||||
public Integer getQueryDefaultLanguageAsInteger() {
|
||||
return getAsInteger(FessConfig.QUERY_DEFAULT_LANGUAGE);
|
||||
public Integer getQueryDefaultLanguagesAsInteger() {
|
||||
return getAsInteger(FessConfig.QUERY_DEFAULT_LANGUAGES);
|
||||
}
|
||||
|
||||
public String getQueryLanguageMapping() {
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package org.codelibs.fess.mylasta.direction;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -23,6 +25,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import javax.naming.directory.Attribute;
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.codelibs.core.exception.ClassNotFoundRuntimeException;
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
|
@ -380,12 +383,29 @@ public interface FessProp {
|
|||
return Boolean.valueOf(getQueryReplaceTermWithPrefixQuery());
|
||||
}
|
||||
|
||||
String getQueryDefaultLanguages();
|
||||
|
||||
String getQueryLanguageMapping();
|
||||
|
||||
public default String getQueryLanguage(final Locale locale) {
|
||||
if (locale == null) {
|
||||
return null;
|
||||
public default String[] getQueryLanguages(final Enumeration<Locale> locales, final String[] requestLangs) {
|
||||
if (StringUtil.isNotBlank(getQueryDefaultLanguages())) {
|
||||
String[] langs = (String[]) propMap.get("queryDefaultLanguages");
|
||||
if (langs == null) {
|
||||
langs = StreamUtil.of(getQueryDefaultLanguages().split(",")).map(s -> s.trim()).toArray(n -> new String[n]);
|
||||
propMap.put("queryDefaultLanguages", langs);
|
||||
|
||||
}
|
||||
return langs;
|
||||
}
|
||||
|
||||
if (requestLangs != null && requestLangs.length != 0) {
|
||||
return requestLangs;
|
||||
}
|
||||
|
||||
if (locales == null) {
|
||||
return StringUtil.EMPTY_STRINGS;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> params = (Map<String, String>) propMap.get(QUERY_LANGUAGE_MAPPING);
|
||||
if (params == null) {
|
||||
|
@ -399,20 +419,23 @@ public interface FessProp {
|
|||
propMap.put(QUERY_LANGUAGE_MAPPING, params);
|
||||
}
|
||||
|
||||
final String language = locale.getLanguage();
|
||||
final String country = locale.getCountry();
|
||||
if (StringUtil.isNotBlank(language)) {
|
||||
if (StringUtil.isNotBlank(country)) {
|
||||
final String lang = language.toLowerCase(Locale.ROOT) + "-" + country.toLowerCase(Locale.ROOT);
|
||||
if (params.containsKey(lang)) {
|
||||
return params.get(lang);
|
||||
final Map<String, String> mapping = params;
|
||||
return Collections.list(locales).stream().map(locale -> {
|
||||
final String language = locale.getLanguage();
|
||||
final String country = locale.getCountry();
|
||||
if (StringUtil.isNotBlank(language)) {
|
||||
if (StringUtil.isNotBlank(country)) {
|
||||
final String lang = language.toLowerCase(Locale.ROOT) + "-" + country.toLowerCase(Locale.ROOT);
|
||||
if (mapping.containsKey(lang)) {
|
||||
return mapping.get(lang);
|
||||
}
|
||||
}
|
||||
if (mapping.containsKey(language)) {
|
||||
return mapping.get(language);
|
||||
}
|
||||
}
|
||||
if (params.containsKey(language)) {
|
||||
return params.get(language);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}).filter(l -> l != null).distinct().toArray(n -> new String[n]);
|
||||
}
|
||||
|
||||
String getSupportedUploadedFiles();
|
||||
|
@ -524,4 +547,5 @@ public interface FessProp {
|
|||
public default boolean isValidCrawlerFileProtocol(final String url) {
|
||||
return StreamUtil.of(getCrawlerFileProtocolsAsArray()).anyMatch(s -> url.startsWith(s));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ index.document.type=doc
|
|||
# query
|
||||
query.max.length=1000
|
||||
query.replace.term.with.prefix.query=true
|
||||
query.default.language=
|
||||
query.default.languages=
|
||||
query.language.mapping=\
|
||||
ar=ar\n\
|
||||
bg=bg\n\
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
package org.codelibs.fess.validation;
|
||||
|
||||
import org.codelibs.fess.unit.UnitFessTestCase;
|
||||
import org.codelibs.fess.validation.UriTypeValidator;
|
||||
|
||||
public class UriTypeValidatorTest extends UnitFessTestCase {
|
||||
public void test_check_ok() {
|
||||
|
|
Loading…
Add table
Reference in a new issue