fix #2069 add query.gsa.meta.prefix and query.gsa.index.field.*

This commit is contained in:
Shinsuke Sugaya 2019-03-28 18:31:52 +09:00
parent da5d7191fd
commit bb75b08bb5
3 changed files with 54 additions and 25 deletions

View file

@ -66,17 +66,8 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
private static final String OUTPUT_XML = "xml"; // or xml_no_dtd
// http://www.google.com/google.dtd.
@Deprecated
private static final String GSA_META_SUFFIX = "_s";
protected String gsaPathPrefix = "/gsa";
protected String gsaMetaPrefix = "MT_";
protected String charsetField = "charset";
protected String contentTypeField = "content_type";
@PostConstruct
public void register() {
if (logger.isInfoEnabled()) {
@ -254,13 +245,12 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
document.put("LANG", lang);
document.remove(fessConfig.getIndexFieldLang());
}
final String gsaMetaPrefix = fessConfig.getQueryGsaMetaPrefix();
for (final Map.Entry<String, Object> entry : document.entrySet()) {
final String name = entry.getKey();
if (StringUtil.isNotBlank(name) && entry.getValue() != null && fessConfig.isGsaResponseFields(name)) {
if (name.startsWith(gsaMetaPrefix)) {
final String tagName =
name.replaceFirst("^" + gsaMetaPrefix, StringUtil.EMPTY).replaceAll(GSA_META_SUFFIX + "\\z",
StringUtil.EMPTY);
final String tagName = name.replaceFirst("^" + gsaMetaPrefix, StringUtil.EMPTY);
if (getFields.contains(tagName)) {
buf.append("<MT N=\"");
buf.append(tagName);
@ -298,9 +288,11 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
buf.append(DocumentUtil.getValue(document, fessConfig.getIndexFieldDocId(), String.class));
document.remove(fessConfig.getIndexFieldDocId());
buf.append("\" ENC=\"");
final String charsetField = fessConfig.getQueryGsaIndexFieldCharset();
String charset = DocumentUtil.getValue(document, charsetField, String.class);
document.remove(charsetField);
if (StringUtil.isBlank(charset)) {
final String contentTypeField = fessConfig.getQueryGsaIndexFieldContentType();
charset = DocumentUtil.getValue(document, contentTypeField, String.class);
document.remove(contentTypeField);
if (StringUtil.isNotBlank(charset)) {
@ -434,7 +426,7 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
}
}
protected class GsaRequestParams extends SearchRequestParams {
protected static class GsaRequestParams extends SearchRequestParams {
private final HttpServletRequest request;
@ -466,6 +458,7 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
for (final String s : getParamValueArray(request, "ex_q")) {
queryList.add(s.trim());
}
final String gsaMetaPrefix = fessConfig.getQueryGsaMetaPrefix();
final String requiredFields = request.getParameter("requiredfields");
if (StringUtil.isNotBlank(requiredFields)) {
queryList.add(gsaMetaPrefix + requiredFields.replace(".", " AND " + gsaMetaPrefix).replace("|", " OR " + gsaMetaPrefix));
@ -641,18 +634,6 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
this.gsaPathPrefix = gsaPathPrefix;
}
public void setGsaMetaPrefix(final String gsaMetaPrefix) {
this.gsaMetaPrefix = gsaMetaPrefix;
}
public void setCharsetField(final String charsetField) {
this.charsetField = charsetField;
}
public void setContentTypeField(final String contentTypeField) {
this.contentTypeField = contentTypeField;
}
@Override
protected void writeHeaders(final HttpServletResponse response) {
ComponentUtil.getFessConfig().getApiGsaResponseHeaderList().forEach(e -> response.setHeader(e.getFirst(), e.getSecond()));

View file

@ -699,6 +699,15 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. */
String QUERY_GSA_DEFAULT_SORT = "query.gsa.default.sort";
/** The key of the configuration. e.g. MT_ */
String QUERY_GSA_META_PREFIX = "query.gsa.meta.prefix";
/** The key of the configuration. e.g. charset */
String QUERY_GSA_INDEX_FIELD_CHARSET = "query.gsa.index.field.charset";
/** The key of the configuration. e.g. content_type */
String QUERY_GSA_INDEX_FIELD_content_type_ = "query.gsa.index.field.content_type.";
/** The key of the configuration. e.g. 4 */
String QUERY_COLLAPSE_MAX_CONCURRENT_GROUP_RESULTS = "query.collapse.max.concurrent.group.results";
@ -3545,6 +3554,27 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
Integer getQueryGsaDefaultSortAsInteger();
/**
* Get the value for the key 'query.gsa.meta.prefix'. <br>
* The value is, e.g. MT_ <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getQueryGsaMetaPrefix();
/**
* Get the value for the key 'query.gsa.index.field.charset'. <br>
* The value is, e.g. charset <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getQueryGsaIndexFieldCharset();
/**
* Get the value for the key 'query.gsa.index.field.content_type.'. <br>
* The value is, e.g. content_type <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getQueryGsaIndexFieldContentType();
/**
* Get the value for the key 'query.collapse.max.concurrent.group.results'. <br>
* The value is, e.g. 4 <br>
@ -6990,6 +7020,18 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
return getAsInteger(FessConfig.QUERY_GSA_DEFAULT_SORT);
}
public String getQueryGsaMetaPrefix() {
return get(FessConfig.QUERY_GSA_META_PREFIX);
}
public String getQueryGsaIndexFieldCharset() {
return get(FessConfig.QUERY_GSA_INDEX_FIELD_CHARSET);
}
public String getQueryGsaIndexFieldContentType() {
return get(FessConfig.QUERY_GSA_INDEX_FIELD_content_type_);
}
public String getQueryCollapseMaxConcurrentGroupResults() {
return get(FessConfig.QUERY_COLLAPSE_MAX_CONCURRENT_GROUP_RESULTS);
}
@ -8429,6 +8471,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
defaultMap.put(FessConfig.QUERY_GSA_RESPONSE_FIELDS, "UE,U,T,RK,S,LANG");
defaultMap.put(FessConfig.QUERY_GSA_DEFAULT_LANG, "en");
defaultMap.put(FessConfig.QUERY_GSA_DEFAULT_SORT, "");
defaultMap.put(FessConfig.QUERY_GSA_META_PREFIX, "MT_");
defaultMap.put(FessConfig.QUERY_GSA_INDEX_FIELD_CHARSET, "charset");
defaultMap.put(FessConfig.QUERY_GSA_INDEX_FIELD_content_type_, "content_type");
defaultMap.put(FessConfig.QUERY_COLLAPSE_MAX_CONCURRENT_GROUP_RESULTS, "4");
defaultMap.put(FessConfig.QUERY_COLLAPSE_INNER_HITS_NAME, "similar_docs");
defaultMap.put(FessConfig.QUERY_COLLAPSE_INNER_HITS_SIZE, "0");

View file

@ -338,6 +338,9 @@ query.additional.not.analyzed.fields=
query.gsa.response.fields=UE,U,T,RK,S,LANG
query.gsa.default.lang=en
query.gsa.default.sort=
query.gsa.meta.prefix=MT_
query.gsa.index.field.charset=charset
query.gsa.index.field.content_type.=content_type
query.collapse.max.concurrent.group.results=4
query.collapse.inner.hits.name=similar_docs
query.collapse.inner.hits.size=0