mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-13 11:06:30 +00:00
Add recent searches filtering (#4476)
This commit is contained in:
parent
d04092e634
commit
a1ebc6be86
@ -84,6 +84,7 @@ public class RecentlySearchedSource implements RecommendationSource {
|
|||||||
.map(bucket -> buildContent(bucket.getKeyAsString()))
|
.map(bucket -> buildContent(bucket.getKeyAsString()))
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
|
.limit(MAX_CONTENT)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Search query to get most recently viewed entities failed", e);
|
log.error("Search query to get most recently viewed entities failed", e);
|
||||||
@ -107,7 +108,7 @@ public class RecentlySearchedSource implements RecommendationSource {
|
|||||||
String lastSearched = "last_searched";
|
String lastSearched = "last_searched";
|
||||||
AggregationBuilder aggregation = AggregationBuilders.terms(ENTITY_AGG_NAME)
|
AggregationBuilder aggregation = AggregationBuilders.terms(ENTITY_AGG_NAME)
|
||||||
.field(DataHubUsageEventConstants.QUERY + ".keyword")
|
.field(DataHubUsageEventConstants.QUERY + ".keyword")
|
||||||
.size(MAX_CONTENT)
|
.size(MAX_CONTENT * 2) // Fetch more than max to account for post-filtering
|
||||||
.order(BucketOrder.aggregation(lastSearched, false))
|
.order(BucketOrder.aggregation(lastSearched, false))
|
||||||
.subAggregation(AggregationBuilders.max(lastSearched).field(DataHubUsageEventConstants.TIMESTAMP));
|
.subAggregation(AggregationBuilders.max(lastSearched).field(DataHubUsageEventConstants.TIMESTAMP));
|
||||||
source.aggregation(aggregation);
|
source.aggregation(aggregation);
|
||||||
@ -118,7 +119,14 @@ public class RecentlySearchedSource implements RecommendationSource {
|
|||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isQueryInvalid(@Nonnull String query) {
|
||||||
|
return query.trim().isEmpty() || query.equals("*");
|
||||||
|
}
|
||||||
|
|
||||||
private Optional<RecommendationContent> buildContent(@Nonnull String query) {
|
private Optional<RecommendationContent> buildContent(@Nonnull String query) {
|
||||||
|
if (isQueryInvalid(query)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
return Optional.of(new RecommendationContent().setValue(query)
|
return Optional.of(new RecommendationContent().setValue(query)
|
||||||
.setParams(new RecommendationParams().setSearchParams(new SearchParams().setQuery(query))));
|
.setParams(new RecommendationParams().setSearchParams(new SearchParams().setQuery(query))));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user