Skip to content
Snippets Groups Projects
Commit bb75b08b authored by Shinsuke Sugaya's avatar Shinsuke Sugaya
Browse files

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

parent da5d7191
Branches
Tags
No related merge requests found
...@@ -66,17 +66,8 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager { ...@@ -66,17 +66,8 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
private static final String OUTPUT_XML = "xml"; // or xml_no_dtd private static final String OUTPUT_XML = "xml"; // or xml_no_dtd
// http://www.google.com/google.dtd. // http://www.google.com/google.dtd.
@Deprecated
private static final String GSA_META_SUFFIX = "_s";
protected String gsaPathPrefix = "/gsa"; protected String gsaPathPrefix = "/gsa";
protected String gsaMetaPrefix = "MT_";
protected String charsetField = "charset";
protected String contentTypeField = "content_type";
@PostConstruct @PostConstruct
public void register() { public void register() {
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
...@@ -254,13 +245,12 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager { ...@@ -254,13 +245,12 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
document.put("LANG", lang); document.put("LANG", lang);
document.remove(fessConfig.getIndexFieldLang()); document.remove(fessConfig.getIndexFieldLang());
} }
final String gsaMetaPrefix = fessConfig.getQueryGsaMetaPrefix();
for (final Map.Entry<String, Object> entry : document.entrySet()) { for (final Map.Entry<String, Object> entry : document.entrySet()) {
final String name = entry.getKey(); final String name = entry.getKey();
if (StringUtil.isNotBlank(name) && entry.getValue() != null && fessConfig.isGsaResponseFields(name)) { if (StringUtil.isNotBlank(name) && entry.getValue() != null && fessConfig.isGsaResponseFields(name)) {
if (name.startsWith(gsaMetaPrefix)) { if (name.startsWith(gsaMetaPrefix)) {
final String tagName = final String tagName = name.replaceFirst("^" + gsaMetaPrefix, StringUtil.EMPTY);
name.replaceFirst("^" + gsaMetaPrefix, StringUtil.EMPTY).replaceAll(GSA_META_SUFFIX + "\\z",
StringUtil.EMPTY);
if (getFields.contains(tagName)) { if (getFields.contains(tagName)) {
buf.append("<MT N=\""); buf.append("<MT N=\"");
buf.append(tagName); buf.append(tagName);
...@@ -298,9 +288,11 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager { ...@@ -298,9 +288,11 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
buf.append(DocumentUtil.getValue(document, fessConfig.getIndexFieldDocId(), String.class)); buf.append(DocumentUtil.getValue(document, fessConfig.getIndexFieldDocId(), String.class));
document.remove(fessConfig.getIndexFieldDocId()); document.remove(fessConfig.getIndexFieldDocId());
buf.append("\" ENC=\""); buf.append("\" ENC=\"");
final String charsetField = fessConfig.getQueryGsaIndexFieldCharset();
String charset = DocumentUtil.getValue(document, charsetField, String.class); String charset = DocumentUtil.getValue(document, charsetField, String.class);
document.remove(charsetField); document.remove(charsetField);
if (StringUtil.isBlank(charset)) { if (StringUtil.isBlank(charset)) {
final String contentTypeField = fessConfig.getQueryGsaIndexFieldContentType();
charset = DocumentUtil.getValue(document, contentTypeField, String.class); charset = DocumentUtil.getValue(document, contentTypeField, String.class);
document.remove(contentTypeField); document.remove(contentTypeField);
if (StringUtil.isNotBlank(charset)) { if (StringUtil.isNotBlank(charset)) {
...@@ -434,7 +426,7 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager { ...@@ -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; private final HttpServletRequest request;
...@@ -466,6 +458,7 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager { ...@@ -466,6 +458,7 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
for (final String s : getParamValueArray(request, "ex_q")) { for (final String s : getParamValueArray(request, "ex_q")) {
queryList.add(s.trim()); queryList.add(s.trim());
} }
final String gsaMetaPrefix = fessConfig.getQueryGsaMetaPrefix();
final String requiredFields = request.getParameter("requiredfields"); final String requiredFields = request.getParameter("requiredfields");
if (StringUtil.isNotBlank(requiredFields)) { if (StringUtil.isNotBlank(requiredFields)) {
queryList.add(gsaMetaPrefix + requiredFields.replace(".", " AND " + gsaMetaPrefix).replace("|", " OR " + gsaMetaPrefix)); queryList.add(gsaMetaPrefix + requiredFields.replace(".", " AND " + gsaMetaPrefix).replace("|", " OR " + gsaMetaPrefix));
...@@ -641,18 +634,6 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager { ...@@ -641,18 +634,6 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
this.gsaPathPrefix = gsaPathPrefix; 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 @Override
protected void writeHeaders(final HttpServletResponse response) { protected void writeHeaders(final HttpServletResponse response) {
ComponentUtil.getFessConfig().getApiGsaResponseHeaderList().forEach(e -> response.setHeader(e.getFirst(), e.getSecond())); ComponentUtil.getFessConfig().getApiGsaResponseHeaderList().forEach(e -> response.setHeader(e.getFirst(), e.getSecond()));
......
...@@ -699,6 +699,15 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction ...@@ -699,6 +699,15 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. */ /** The key of the configuration. e.g. */
String QUERY_GSA_DEFAULT_SORT = "query.gsa.default.sort"; 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 */ /** The key of the configuration. e.g. 4 */
String QUERY_COLLAPSE_MAX_CONCURRENT_GROUP_RESULTS = "query.collapse.max.concurrent.group.results"; 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 ...@@ -3545,6 +3554,27 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/ */
Integer getQueryGsaDefaultSortAsInteger(); 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> * Get the value for the key 'query.collapse.max.concurrent.group.results'. <br>
* The value is, e.g. 4 <br> * The value is, e.g. 4 <br>
...@@ -6990,6 +7020,18 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction ...@@ -6990,6 +7020,18 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
return getAsInteger(FessConfig.QUERY_GSA_DEFAULT_SORT); 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() { public String getQueryCollapseMaxConcurrentGroupResults() {
return get(FessConfig.QUERY_COLLAPSE_MAX_CONCURRENT_GROUP_RESULTS); return get(FessConfig.QUERY_COLLAPSE_MAX_CONCURRENT_GROUP_RESULTS);
} }
...@@ -8429,6 +8471,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction ...@@ -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_RESPONSE_FIELDS, "UE,U,T,RK,S,LANG");
defaultMap.put(FessConfig.QUERY_GSA_DEFAULT_LANG, "en"); defaultMap.put(FessConfig.QUERY_GSA_DEFAULT_LANG, "en");
defaultMap.put(FessConfig.QUERY_GSA_DEFAULT_SORT, ""); 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_MAX_CONCURRENT_GROUP_RESULTS, "4");
defaultMap.put(FessConfig.QUERY_COLLAPSE_INNER_HITS_NAME, "similar_docs"); defaultMap.put(FessConfig.QUERY_COLLAPSE_INNER_HITS_NAME, "similar_docs");
defaultMap.put(FessConfig.QUERY_COLLAPSE_INNER_HITS_SIZE, "0"); defaultMap.put(FessConfig.QUERY_COLLAPSE_INNER_HITS_SIZE, "0");
......
...@@ -338,6 +338,9 @@ query.additional.not.analyzed.fields= ...@@ -338,6 +338,9 @@ query.additional.not.analyzed.fields=
query.gsa.response.fields=UE,U,T,RK,S,LANG query.gsa.response.fields=UE,U,T,RK,S,LANG
query.gsa.default.lang=en query.gsa.default.lang=en
query.gsa.default.sort= 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.max.concurrent.group.results=4
query.collapse.inner.hits.name=similar_docs query.collapse.inner.hits.name=similar_docs
query.collapse.inner.hits.size=0 query.collapse.inner.hits.size=0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment