remove search field logs for aggs
This commit is contained in:
parent
07a440a215
commit
0cd9c877fa
3 changed files with 29 additions and 29 deletions
|
@ -41,20 +41,20 @@ public class QueryContext {
|
|||
|
||||
private final Set<String> highlightedQuerySet = new HashSet<>();
|
||||
|
||||
private Map<String, List<String>> fieldLogMap;
|
||||
private Map<String, List<String>> fieldLogMap = null;
|
||||
|
||||
public QueryContext(final String queryString) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public QueryContext(final String queryString, final boolean fieldLogEnable) {
|
||||
this.queryString = queryString;
|
||||
LaRequestUtil.getOptionalRequest().ifPresent(request -> {
|
||||
request.setAttribute(Constants.HIGHLIGHT_QUERIES, highlightedQuerySet);
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<String, List<String>> existFieldLogMap = (Map<String, List<String>>) request.getAttribute(Constants.FIELD_LOGS);
|
||||
if (existFieldLogMap != null) {
|
||||
fieldLogMap = existFieldLogMap;
|
||||
} else {
|
||||
fieldLogMap = new HashMap<>();
|
||||
if (fieldLogEnable) {
|
||||
fieldLogMap = (Map<String, List<String>>) request.getAttribute(Constants.FIELD_LOGS);
|
||||
if (fieldLogMap == null) {
|
||||
fieldLogMap = new HashMap<>();
|
||||
request.setAttribute(Constants.FIELD_LOGS, fieldLogMap);
|
||||
}
|
||||
}
|
||||
request.setAttribute(Constants.FIELD_LOGS, fieldLogMap);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -94,6 +94,10 @@ public class QueryContext {
|
|||
}
|
||||
|
||||
public void addFieldLog(String field, String text) {
|
||||
if (fieldLogMap == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> list = fieldLogMap.get(field);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
|
|
|
@ -855,21 +855,18 @@ public class FessEsClient implements Client {
|
|||
});
|
||||
StreamUtil.of(facetInfo.query).forEach(
|
||||
fq -> {
|
||||
final QueryContext facetContext = queryHelper.buildBaseQuery(fq, c -> {});
|
||||
if (facetContext != null) {
|
||||
final String encodedFacetQuery = BaseEncoding.base64().encode(fq.getBytes(StandardCharsets.UTF_8));
|
||||
final FilterAggregationBuilder filterBuilder =
|
||||
AggregationBuilders.filter(Constants.FACET_QUERY_PREFIX + encodedFacetQuery).filter(
|
||||
facetContext.getQueryBuilder());
|
||||
// TODO order
|
||||
if (facetInfo.limit != null) {
|
||||
// TODO
|
||||
// filterBuilder.size(Integer.parseInt(facetInfo .limit));
|
||||
}
|
||||
searchRequestBuilder.addAggregation(filterBuilder);
|
||||
} else {
|
||||
throw new FessSearchQueryException("Invalid facet query: " + fq);
|
||||
final QueryContext facetContext = new QueryContext(fq, false);
|
||||
queryHelper.buildBaseQuery(facetContext, c -> {});
|
||||
final String encodedFacetQuery = BaseEncoding.base64().encode(fq.getBytes(StandardCharsets.UTF_8));
|
||||
final FilterAggregationBuilder filterBuilder =
|
||||
AggregationBuilders.filter(Constants.FACET_QUERY_PREFIX + encodedFacetQuery).filter(
|
||||
facetContext.getQueryBuilder());
|
||||
// TODO order
|
||||
if (facetInfo.limit != null) {
|
||||
// TODO
|
||||
// filterBuilder.size(Integer.parseInt(facetInfo .limit));
|
||||
}
|
||||
searchRequestBuilder.addAggregation(filterBuilder);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -212,7 +212,8 @@ public class QueryHelper implements Serializable {
|
|||
q = query;
|
||||
}
|
||||
|
||||
final QueryContext queryContext = buildBaseQuery(q, context);
|
||||
final QueryContext queryContext = new QueryContext(q, true);
|
||||
buildBaseQuery(queryContext, context);
|
||||
|
||||
if (keyMatchHelper != null) {
|
||||
final List<String> docIdQueryList = keyMatchHelper.getDocIdQueryList();
|
||||
|
@ -245,11 +246,10 @@ public class QueryHelper implements Serializable {
|
|||
return queryContext;
|
||||
}
|
||||
|
||||
public QueryContext buildBaseQuery(final String queryString, final Consumer<QueryContext> context) {
|
||||
public void buildBaseQuery(final QueryContext queryContext, final Consumer<QueryContext> context) {
|
||||
final QueryParser queryParser = getQueryParser();
|
||||
try {
|
||||
final QueryContext queryContext = new QueryContext(queryString);
|
||||
final Query query = queryParser.parse(queryString);
|
||||
final Query query = queryParser.parse(queryContext.getQueryString());
|
||||
final QueryBuilder queryBuilder = convertQuery(queryContext, query);
|
||||
if (queryBuilder != null) {
|
||||
queryContext.setQueryBuilder(queryBuilder);
|
||||
|
@ -257,10 +257,9 @@ public class QueryHelper implements Serializable {
|
|||
queryContext.setQueryBuilder(QueryBuilders.matchAllQuery());
|
||||
}
|
||||
context.accept(queryContext);
|
||||
return queryContext;
|
||||
} catch (final ParseException e) {
|
||||
throw new InvalidQueryException(messages -> messages.addErrorsInvalidQueryParseError(ActionMessages.GLOBAL_PROPERTY_KEY),
|
||||
"Invalid query: " + queryString);
|
||||
"Invalid query: " + queryContext.getQueryString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue