diff --git a/src/main/java/org/codelibs/fess/entity/FacetInfo.java b/src/main/java/org/codelibs/fess/entity/FacetInfo.java index aeaa6bf1c..b427201d8 100644 --- a/src/main/java/org/codelibs/fess/entity/FacetInfo.java +++ b/src/main/java/org/codelibs/fess/entity/FacetInfo.java @@ -15,13 +15,13 @@ */ package org.codelibs.fess.entity; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import javax.annotation.PostConstruct; import org.codelibs.core.lang.StringUtil; +import org.codelibs.core.stream.StreamUtil; +import org.codelibs.fess.mylasta.direction.FessConfig; import org.codelibs.fess.util.ComponentUtil; import org.elasticsearch.search.aggregations.BucketOrder; import org.slf4j.Logger; @@ -44,20 +44,23 @@ public class FacetInfo { @PostConstruct public void init() { - final String[] fileTypes = ComponentUtil.getFileTypeHelper().getTypes(); - if (fileTypes.length > 0) { - final List queryList = new ArrayList<>(); - for (String s : query) { - queryList.add(s); - } - final String field = ComponentUtil.getFessConfig().getIndexFieldFiletype(); - for (String s : fileTypes) { - queryList.add(field + ":" + s); - } - query = queryList.toArray(n -> new String[n]); - if (logger.isDebugEnabled()) { - logger.debug("loaded facet query: {}", queryList); - } + final FessConfig fessConfig = ComponentUtil.getFessConfig(); + if (StringUtil.isNotBlank(fessConfig.getQueryFacetFields())) { + field = + StreamUtil.split(fessConfig.getQueryFacetFields(), ",").get( + stream -> stream.map(String::trim).filter(StringUtil::isNotEmpty).distinct().toArray(n -> new String[n])); + } + if (StringUtil.isNotBlank(fessConfig.getQueryFacetFieldsSize())) { + size = fessConfig.getQueryFacetFieldsSizeAsInteger(); + } + if (StringUtil.isNotBlank(fessConfig.getQueryFacetFieldsMinDocCount())) { + minDocCount = Long.parseLong(fessConfig.getQueryFacetFieldsMinDocCount()); + } + if (StringUtil.isNotBlank(fessConfig.getQueryFacetFieldsSort())) { + sort = fessConfig.getQueryFacetFieldsSort(); + } + if (StringUtil.isNotBlank(fessConfig.getQueryFacetFieldsMissing())) { + missing = fessConfig.getQueryFacetFieldsMissing(); } } @@ -81,10 +84,22 @@ public class FacetInfo { return BucketOrder.count(false); } + public void addQuery(final String s) { + if (query == null) { + query = new String[] { s }; + } else { + final String[] newQuery = Arrays.copyOf(query, query.length + 1); + newQuery[query.length] = s; + query = newQuery; + } + if (logger.isDebugEnabled()) { + logger.debug("loaded facet query: {}", s); + } + } + @Override public String toString() { return "FacetInfo [field=" + Arrays.toString(field) + ", query=" + Arrays.toString(query) + ", size=" + size + ", minDocCount=" + minDocCount + ", sort=" + sort + ", missing=" + missing + "]"; } - } diff --git a/src/main/java/org/codelibs/fess/entity/FacetQueryView.java b/src/main/java/org/codelibs/fess/entity/FacetQueryView.java index 867275076..0b1731c87 100644 --- a/src/main/java/org/codelibs/fess/entity/FacetQueryView.java +++ b/src/main/java/org/codelibs/fess/entity/FacetQueryView.java @@ -58,6 +58,9 @@ public class FacetQueryView { logger.debug("updated query map: {}", queryMap); } } + + final FacetInfo facetInfo = ComponentUtil.getComponent("facetInfo"); + queryMap.values().stream().distinct().forEach(facetInfo::addQuery); } public String getTitle() { diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java index 6341e76d6..11276561f 100644 --- a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java +++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java @@ -914,6 +914,21 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction /** The key of the configuration. e.g. 0.5 */ String QUERY_BOOST_CONTENT_LANG = "query.boost.content.lang"; + /** The key of the configuration. e.g. label */ + String QUERY_FACET_FIELDS = "query.facet.fields"; + + /** The key of the configuration. e.g. 100 */ + String QUERY_FACET_FIELDS_SIZE = "query.facet.fields.size"; + + /** The key of the configuration. e.g. 1 */ + String QUERY_FACET_FIELDS_min_doc_count = "query.facet.fields.min_doc_count"; + + /** The key of the configuration. e.g. count.desc */ + String QUERY_FACET_FIELDS_SORT = "query.facet.fields.sort"; + + /** The key of the configuration. e.g. */ + String QUERY_FACET_FIELDS_MISSING = "query.facet.fields.missing"; + /** The key of the configuration. e.g. labels.facet_timestamp_title:labels.facet_timestamp_1day=timestamp:[now/d-1d TO *] labels.facet_timestamp_1week=timestamp:[now/d-7d TO *] labels.facet_timestamp_1month=timestamp:[now/d-1M TO *] labels.facet_timestamp_1year=timestamp:[now/d-1y TO *] labels.facet_contentLength_title:labels.facet_contentLength_10k=content_length:[0 TO 9999] labels.facet_contentLength_10kto100k=content_length:[10000 TO 99999] labels.facet_contentLength_100kto500k=content_length:[100000 TO 499999] labels.facet_contentLength_500kto1m=content_length:[500000 TO 999999] labels.facet_contentLength_1m=content_length:[1000000 TO *] labels.facet_filetype_title:labels.facet_filetype_html=filetype:html labels.facet_filetype_word=filetype:word labels.facet_filetype_excel=filetype:excel labels.facet_filetype_powerpoint=filetype:powerpoint labels.facet_filetype_odt=filetype:odt labels.facet_filetype_ods=filetype:ods labels.facet_filetype_odp=filetype:odp labels.facet_filetype_pdf=filetype:pdf labels.facet_filetype_txt=filetype:txt labels.facet_filetype_others=filetype:others @@ -4146,13 +4161,72 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction */ java.math.BigDecimal getQueryBoostContentLangAsDecimal(); + /** + * Get the value for the key 'query.facet.fields'.
+ * The value is, e.g. label
+ * comment: facet + * @return The value of found property. (NotNull: if not found, exception but basically no way) + */ + String getQueryFacetFields(); + + /** + * Get the value for the key 'query.facet.fields.size'.
+ * The value is, e.g. 100
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + */ + String getQueryFacetFieldsSize(); + + /** + * Get the value for the key 'query.facet.fields.size' as {@link Integer}.
+ * The value is, e.g. 100
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + * @throws NumberFormatException When the property is not integer. + */ + Integer getQueryFacetFieldsSizeAsInteger(); + + /** + * Get the value for the key 'query.facet.fields.min_doc_count'.
+ * The value is, e.g. 1
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + */ + String getQueryFacetFieldsMinDocCount(); + + /** + * Get the value for the key 'query.facet.fields.min_doc_count' as {@link Integer}.
+ * The value is, e.g. 1
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + * @throws NumberFormatException When the property is not integer. + */ + Integer getQueryFacetFieldsMinDocCountAsInteger(); + + /** + * Get the value for the key 'query.facet.fields.sort'.
+ * The value is, e.g. count.desc
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + */ + String getQueryFacetFieldsSort(); + + /** + * Get the value for the key 'query.facet.fields.missing'.
+ * The value is, e.g.
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + */ + String getQueryFacetFieldsMissing(); + + /** + * Get the value for the key 'query.facet.fields.missing' as {@link Integer}.
+ * The value is, e.g.
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + * @throws NumberFormatException When the property is not integer. + */ + Integer getQueryFacetFieldsMissingAsInteger(); + /** * Get the value for the key 'query.facet.queries'.
* The value is, e.g. labels.facet_timestamp_title:labels.facet_timestamp_1day=timestamp:[now/d-1d TO *] labels.facet_timestamp_1week=timestamp:[now/d-7d TO *] labels.facet_timestamp_1month=timestamp:[now/d-1M TO *] labels.facet_timestamp_1year=timestamp:[now/d-1y TO *] labels.facet_contentLength_title:labels.facet_contentLength_10k=content_length:[0 TO 9999] labels.facet_contentLength_10kto100k=content_length:[10000 TO 99999] labels.facet_contentLength_100kto500k=content_length:[100000 TO 499999] labels.facet_contentLength_500kto1m=content_length:[500000 TO 999999] labels.facet_contentLength_1m=content_length:[1000000 TO *] labels.facet_filetype_title:labels.facet_filetype_html=filetype:html labels.facet_filetype_word=filetype:word labels.facet_filetype_excel=filetype:excel labels.facet_filetype_powerpoint=filetype:powerpoint labels.facet_filetype_odt=filetype:odt labels.facet_filetype_ods=filetype:ods labels.facet_filetype_odp=filetype:odp labels.facet_filetype_pdf=filetype:pdf labels.facet_filetype_txt=filetype:txt labels.facet_filetype_others=filetype:others
- * comment: facet * @return The value of found property. (NotNull: if not found, exception but basically no way) */ String getQueryFacetQueries(); @@ -7576,6 +7650,38 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction return getAsDecimal(FessConfig.QUERY_BOOST_CONTENT_LANG); } + public String getQueryFacetFields() { + return get(FessConfig.QUERY_FACET_FIELDS); + } + + public String getQueryFacetFieldsSize() { + return get(FessConfig.QUERY_FACET_FIELDS_SIZE); + } + + public Integer getQueryFacetFieldsSizeAsInteger() { + return getAsInteger(FessConfig.QUERY_FACET_FIELDS_SIZE); + } + + public String getQueryFacetFieldsMinDocCount() { + return get(FessConfig.QUERY_FACET_FIELDS_min_doc_count); + } + + public Integer getQueryFacetFieldsMinDocCountAsInteger() { + return getAsInteger(FessConfig.QUERY_FACET_FIELDS_min_doc_count); + } + + public String getQueryFacetFieldsSort() { + return get(FessConfig.QUERY_FACET_FIELDS_SORT); + } + + public String getQueryFacetFieldsMissing() { + return get(FessConfig.QUERY_FACET_FIELDS_MISSING); + } + + public Integer getQueryFacetFieldsMissingAsInteger() { + return getAsInteger(FessConfig.QUERY_FACET_FIELDS_MISSING); + } + public String getQueryFacetQueries() { return get(FessConfig.QUERY_FACET_QUERIES); } @@ -8975,6 +9081,11 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction 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_FACET_FIELDS, "label"); + defaultMap.put(FessConfig.QUERY_FACET_FIELDS_SIZE, "100"); + defaultMap.put(FessConfig.QUERY_FACET_FIELDS_min_doc_count, "1"); + defaultMap.put(FessConfig.QUERY_FACET_FIELDS_SORT, "count.desc"); + defaultMap.put(FessConfig.QUERY_FACET_FIELDS_MISSING, ""); defaultMap .put(FessConfig.QUERY_FACET_QUERIES, "labels.facet_timestamp_title:labels.facet_timestamp_1day=timestamp:[now/d-1d TO *]\tlabels.facet_timestamp_1week=timestamp:[now/d-7d TO *]\tlabels.facet_timestamp_1month=timestamp:[now/d-1M TO *]\tlabels.facet_timestamp_1year=timestamp:[now/d-1y TO *]\nlabels.facet_contentLength_title:labels.facet_contentLength_10k=content_length:[0 TO 9999]\tlabels.facet_contentLength_10kto100k=content_length:[10000 TO 99999]\tlabels.facet_contentLength_100kto500k=content_length:[100000 TO 499999]\tlabels.facet_contentLength_500kto1m=content_length:[500000 TO 999999]\tlabels.facet_contentLength_1m=content_length:[1000000 TO *]\nlabels.facet_filetype_title:labels.facet_filetype_html=filetype:html\tlabels.facet_filetype_word=filetype:word\tlabels.facet_filetype_excel=filetype:excel\tlabels.facet_filetype_powerpoint=filetype:powerpoint\tlabels.facet_filetype_odt=filetype:odt\tlabels.facet_filetype_ods=filetype:ods\tlabels.facet_filetype_odp=filetype:odp\tlabels.facet_filetype_pdf=filetype:pdf\tlabels.facet_filetype_txt=filetype:txt\tlabels.facet_filetype_others=filetype:others\n"); diff --git a/src/main/resources/app.xml b/src/main/resources/app.xml index fbc219053..fc8b2575d 100644 --- a/src/main/resources/app.xml +++ b/src/main/resources/app.xml @@ -49,23 +49,6 @@ org.apache.lucene.queryparser.classic.QueryParser$Operator.AND - "count.desc" - 100 - 1 - ["label"] - [ - "timestamp:[now/d-1d TO *]", - "timestamp:[now/d-7d TO *]", - "timestamp:[now/d-1M TO *]", - "timestamp:[now/d-1y TO *]", - "content_length:[0 TO 9999]", - "content_length:[10000 TO 99999]", - "content_length:[100000 TO 499999]", - "content_length:[500000 TO 999999]", - "content_length:[1000000 TO *]", - "filetype:others" - ] - facetInfo diff --git a/src/main/resources/fess_config.properties b/src/main/resources/fess_config.properties index da1072c55..c35d59cc4 100644 --- a/src/main/resources/fess_config.properties +++ b/src/main/resources/fess_config.properties @@ -500,6 +500,11 @@ query.boost.content=0.005 query.boost.content.lang=0.5 # facet +query.facet.fields=label +query.facet.fields.size=100 +query.facet.fields.min_doc_count=1 +query.facet.fields.sort=count.desc +query.facet.fields.missing= query.facet.queries=\ labels.facet_timestamp_title:\ labels.facet_timestamp_1day=timestamp:[now/d-1d TO *]\t\ diff --git a/src/test/java/org/codelibs/fess/helper/ViewHelperTest.java b/src/test/java/org/codelibs/fess/helper/ViewHelperTest.java index a275ec1ed..93b28c9be 100644 --- a/src/test/java/org/codelibs/fess/helper/ViewHelperTest.java +++ b/src/test/java/org/codelibs/fess/helper/ViewHelperTest.java @@ -25,6 +25,7 @@ import java.util.Set; import org.codelibs.core.io.FileUtil; import org.codelibs.core.misc.DynamicProperties; +import org.codelibs.fess.entity.FacetInfo; import org.codelibs.fess.entity.FacetQueryView; import org.codelibs.fess.es.config.exentity.PathMapping; import org.codelibs.fess.mylasta.direction.FessConfig; @@ -56,6 +57,8 @@ public class ViewHelperTest extends UnitFessTestCase { ComponentUtil.register(pathMappingHelper, "pathMappingHelper"); FileTypeHelper fileTypeHelper = new FileTypeHelper(); ComponentUtil.register(fileTypeHelper, "fileTypeHelper"); + FacetInfo facetInfo = new FacetInfo(); + ComponentUtil.register(facetInfo, "facetInfo"); viewHelper = new ViewHelper(); viewHelper.init(); }