Skip to content

Commit

Permalink
fix #2835 Add interface for rewriting search request parameters befor…
Browse files Browse the repository at this point in the history
…e processing
  • Loading branch information
marevol committed Jul 26, 2024
1 parent 9999aad commit 9066999
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/main/java/org/codelibs/fess/helper/SearchHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.codelibs.fess.helper;

import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -72,15 +73,24 @@ public class SearchHelper {

private static final Logger logger = LogManager.getLogger(SearchHelper.class);

// ===================================================================================
// Variable
//

protected SearchRequestParamsRewriter[] searchRequestParamsRewriters = new SearchRequestParamsRewriter[0];

// ===================================================================================
// Method
// ==============

public void search(final SearchRequestParams params, final SearchRenderData data, final OptionalThing<FessUserBean> userBean) {
public void search(final SearchRequestParams searchRequestParams, final SearchRenderData data,
final OptionalThing<FessUserBean> userBean) {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final long startTime = systemHelper.getCurrentTimeAsLong();
final long requestedTime = startTime;

final SearchRequestParams params = rewrite(searchRequestParams);

LaRequestUtil.getOptionalRequest().ifPresent(request -> {
request.setAttribute(Constants.REQUEST_LANGUAGES, params.getLanguages());
request.setAttribute(Constants.REQUEST_QUERIES, params.getQuery());
Expand Down Expand Up @@ -354,4 +364,21 @@ public boolean bulkUpdate(final Consumer<BulkRequestBuilder> consumer) {
throw new SearchEngineClientException("Failed to update bulk data.", e);
}
}

protected SearchRequestParams rewrite(final SearchRequestParams params) {
SearchRequestParams newParams = params;
for (final SearchRequestParamsRewriter rewriter : searchRequestParamsRewriters) {
newParams = rewriter.rewrite(newParams);
}
return newParams;
}

public void addRewriter(final SearchRequestParamsRewriter rewriter) {
searchRequestParamsRewriters = Arrays.copyOf(searchRequestParamsRewriters, searchRequestParamsRewriters.length + 1);
searchRequestParamsRewriters[searchRequestParamsRewriters.length - 1] = rewriter;
}

public interface SearchRequestParamsRewriter {
SearchRequestParams rewrite(SearchRequestParams params);
}
}

0 comments on commit 9066999

Please sign in to comment.