Selaa lähdekoodia

fix #1752 add query.additional.default.fields

Shinsuke Sugaya 7 vuotta sitten
vanhempi
commit
0c4231a3ce

+ 25 - 4
src/main/java/org/codelibs/fess/helper/QueryHelper.java

@@ -50,6 +50,7 @@ import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.search.WildcardQuery;
 import org.apache.lucene.util.BytesRef;
 import org.codelibs.core.lang.StringUtil;
+import org.codelibs.core.misc.Pair;
 import org.codelibs.fess.Constants;
 import org.codelibs.fess.entity.FacetInfo;
 import org.codelibs.fess.entity.GeoInfo;
@@ -131,6 +132,8 @@ public class QueryHelper {
 
     protected List<QueryRescorer> queryRescorerList = new ArrayList<>();
 
+    protected List<Pair<String, Float>> additionalDefaultList = new ArrayList<>();
+
     @PostConstruct
     public void init() {
         final FessConfig fessConfig = ComponentUtil.getFessConfig();
@@ -311,6 +314,20 @@ public class QueryHelper {
         }
         split(fessConfig.getQueryAdditionalAnalyzedFields(), ",").of(
                 stream -> stream.map(s -> s.trim()).filter(StringUtil::isNotBlank).forEach(s -> notAnalyzedFieldSet.remove(s)));
+        split(fessConfig.getQueryAdditionalDefaultFields(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).map(s -> {
+            final Pair<String, Float> pair = new Pair<>();
+            final String[] values = s.split(":");
+            if (values.length == 1) {
+                pair.setFirst(values[0].trim());
+                pair.setSecond(1.0f);
+            } else if (values.length > 1) {
+                pair.setFirst(values[0]);
+                pair.setSecond(Float.parseFloat(values[1]));
+            } else {
+                return null;
+            }
+            return pair;
+        }).forEach(additionalDefaultList::add));
     }
 
     public QueryContext build(final SearchRequestType searchRequestType, final String query, final Consumer<QueryContext> context) {
@@ -626,7 +643,7 @@ public class QueryHelper {
         return QueryBuilders.prefixQuery(ComponentUtil.getFessConfig().getIndexFieldSite(), text).boost(boost);
     }
 
-    private QueryBuilder convertPhraseQuery(final QueryContext context, final PhraseQuery query, final float boost) {
+    protected QueryBuilder convertPhraseQuery(final QueryContext context, final PhraseQuery query, final float boost) {
         final Term[] terms = query.getTerms();
         if (terms.length == 0) {
             throw new InvalidQueryException(messages -> messages.addErrorsInvalidQueryUnknown(UserMessages.GLOBAL_PROPERTY_KEY),
@@ -640,7 +657,7 @@ public class QueryHelper {
         return buildDefaultQueryBuilder((f, b) -> buildMatchPhraseQuery(f, text).boost(b * boost));
     }
 
-    private boolean isSearchField(final String field) {
+    protected boolean isSearchField(final String field) {
         for (final String searchField : searchFields) {
             if (searchField.equals(field)) {
                 return true;
@@ -649,7 +666,7 @@ public class QueryHelper {
         return false;
     }
 
-    private QueryBuilder buildDefaultQueryBuilder(final DefaultQueryBuilderFunction builder) {
+    protected QueryBuilder buildDefaultQueryBuilder(final DefaultQueryBuilderFunction builder) {
         final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
         final FessConfig fessConfig = ComponentUtil.getFessConfig();
         final QueryBuilder titleQuery =
@@ -670,6 +687,10 @@ public class QueryHelper {
                                             .getQueryBoostContentLangAsDecimal().floatValue());
                             boolQuery.should(contentLangQuery);
                         })));
+        additionalDefaultList.stream().forEach(f -> {
+            final QueryBuilder query = builder.apply(f.getFirst(), f.getSecond());
+            boolQuery.should(query);
+        });
         return boolQuery;
     }
 
@@ -683,7 +704,7 @@ public class QueryHelper {
                         (String[]) request.getAttribute(Constants.REQUEST_LANGUAGES)));
     }
 
-    private boolean isSortField(final String field) {
+    protected boolean isSortField(final String field) {
         for (final String f : sortFields) {
             if (f.equals(field)) {
                 return true;

+ 29 - 2
src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java

@@ -566,6 +566,9 @@ public class FessLabels extends UserMessages {
     /** The key of the message: Job Log */
     public static final String LABELS_menu_jobLog = "{labels.menu_jobLog}";
 
+    /** The key of the message: Search Log */
+    public static final String LABELS_menu_searchLog = "{labels.menu_searchLog}";
+
     /** The key of the message: Failure URL */
     public static final String LABELS_menu_failure_url = "{labels.menu_failure_url}";
 
@@ -2517,10 +2520,10 @@ public class FessLabels extends UserMessages {
     /** The key of the message: Destination Indicator */
     public static final String LABELS_DESTINATION_INDICATOR = "{labels.destinationIndicator}";
 
-    /** The key of the message: Internationali SDNNumber */
+    /** The key of the message: International ISDN Number */
     public static final String LABELS_user_internationaliSDNNumber = "{labels.user_internationaliSDNNumber}";
 
-    /** The key of the message: Internationali SDNNumber */
+    /** The key of the message: International ISDN Number */
     public static final String LABELS_INTERNATIONALISDN_NUMBER = "{labels.internationaliSDNNumber}";
 
     /** The key of the message: State */
@@ -2757,6 +2760,30 @@ public class FessLabels extends UserMessages {
     /** The key of the message: past year */
     public static final String LABELS_advance_search_timestamp_pastyear = "{labels.advance_search_timestamp_pastyear}";
 
+    /** The key of the message: Search Log */
+    public static final String LABELS_searchlog_configuration = "{labels.searchlog_configuration}";
+
+    /** The key of the message: Search Log */
+    public static final String LABELS_searchlog_title = "{labels.searchlog_title}";
+
+    /** The key of the message: Log Type */
+    public static final String LABELS_searchlog_log_type = "{labels.searchlog_log_type}";
+
+    /** The key of the message: Search Log */
+    public static final String LABELS_searchlog_log_type_search = "{labels.searchlog_log_type_search}";
+
+    /** The key of the message: Click Log */
+    public static final String LABELS_searchlog_log_type_click = "{labels.searchlog_log_type_click}";
+
+    /** The key of the message: Favorite Log */
+    public static final String LABELS_searchlog_log_type_favorite = "{labels.searchlog_log_type_favorite}";
+
+    /** The key of the message: Message */
+    public static final String LABELS_searchlog_log_message = "{labels.searchlog_log_message}";
+
+    /** The key of the message: Time */
+    public static final String LABELS_searchlog_requested_time = "{labels.searchlog_requested_time}";
+
     /**
      * Assert the property is not null.
      * @param property The value of the property. (NotNull)

+ 27 - 0
src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java

@@ -602,6 +602,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. 100000 */
     String QUERY_MAX_SEARCH_RESULT_OFFSET = "query.max.search.result.offset";
 
+    /** The key of the configuration. e.g.  */
+    String QUERY_ADDITIONAL_DEFAULT_FIELDS = "query.additional.default.fields";
+
     /** The key of the configuration. e.g.  */
     String QUERY_ADDITIONAL_RESPONSE_FIELDS = "query.additional.response.fields";
 
@@ -3145,6 +3148,21 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
      */
     Integer getQueryMaxSearchResultOffsetAsInteger();
 
+    /**
+     * Get the value for the key 'query.additional.default.fields'. <br>
+     * The value is, e.g.  <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getQueryAdditionalDefaultFields();
+
+    /**
+     * Get the value for the key 'query.additional.default.fields' 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 getQueryAdditionalDefaultFieldsAsInteger();
+
     /**
      * Get the value for the key 'query.additional.response.fields'. <br>
      * The value is, e.g.  <br>
@@ -6791,6 +6809,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             return getAsInteger(FessConfig.QUERY_MAX_SEARCH_RESULT_OFFSET);
         }
 
+        public String getQueryAdditionalDefaultFields() {
+            return get(FessConfig.QUERY_ADDITIONAL_DEFAULT_FIELDS);
+        }
+
+        public Integer getQueryAdditionalDefaultFieldsAsInteger() {
+            return getAsInteger(FessConfig.QUERY_ADDITIONAL_DEFAULT_FIELDS);
+        }
+
         public String getQueryAdditionalResponseFields() {
             return get(FessConfig.QUERY_ADDITIONAL_RESPONSE_FIELDS);
         }
@@ -8428,6 +8454,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             defaultMap.put(FessConfig.QUERY_HIGHLIGHT_TAG_POST, "</strong>");
             defaultMap.put(FessConfig.QUERY_HIGHLIGHT_CONTENT_DESCRIPTION_FIELDS, "hl_content,digest");
             defaultMap.put(FessConfig.QUERY_MAX_SEARCH_RESULT_OFFSET, "100000");
+            defaultMap.put(FessConfig.QUERY_ADDITIONAL_DEFAULT_FIELDS, "");
             defaultMap.put(FessConfig.QUERY_ADDITIONAL_RESPONSE_FIELDS, "");
             defaultMap.put(FessConfig.QUERY_ADDITIONAL_API_RESPONSE_FIELDS, "");
             defaultMap.put(FessConfig.QUERY_ADDITIONAL_SCROLL_RESPONSE_FIELDS, "");

+ 1 - 0
src/main/resources/fess_config.properties

@@ -301,6 +301,7 @@ query.highlight.tag.pre=<strong>
 query.highlight.tag.post=</strong>
 query.highlight.content.description.fields=hl_content,digest
 query.max.search.result.offset=100000
+query.additional.default.fields=
 query.additional.response.fields=
 query.additional.api.response.fields=
 query.additional.scroll.response.fields=