diff --git a/metadata-io/src/main/java/com/linkedin/metadata/search/SearchService.java b/metadata-io/src/main/java/com/linkedin/metadata/search/SearchService.java index d2739fc813b45..41c8de3c553db 100644 --- a/metadata-io/src/main/java/com/linkedin/metadata/search/SearchService.java +++ b/metadata-io/src/main/java/com/linkedin/metadata/search/SearchService.java @@ -62,7 +62,7 @@ public Map docCountPerEntity(@Nonnull List entityNames) { public SearchResult search(@Nonnull List entityNames, @Nonnull String input, @Nullable Filter postFilters, @Nullable SortCriterion sortCriterion, int from, int size, @Nullable SearchFlags searchFlags) { SearchResult result = - _cachingEntitySearchService.search(entityNames, input, postFilters, sortCriterion, from, size, searchFlags, null); + _cachingEntitySearchService.search(getEntitiesToSearch(entityNames), input, postFilters, sortCriterion, from, size, searchFlags, null); try { return result.copy().setEntities(new SearchEntityArray(_searchRanker.rank(result.getEntities()))); @@ -109,14 +109,7 @@ public SearchResult searchAcrossEntities(@Nonnull List entities, @Nonnul facets = new ArrayList<>(facets); facets.add(INDEX_VIRTUAL_FIELD); } - List nonEmptyEntities; - List lowercaseEntities = entities.stream().map(String::toLowerCase).collect(Collectors.toList()); - try (Timer.Context ignored = MetricUtils.timer(this.getClass(), "getNonEmptyEntities").time()) { - nonEmptyEntities = _entityDocCountCache.getNonEmptyEntities(); - } - if (!entities.isEmpty()) { - nonEmptyEntities = nonEmptyEntities.stream().filter(lowercaseEntities::contains).collect(Collectors.toList()); - } + List nonEmptyEntities = getEntitiesToSearch(entities); SearchResult result = _cachingEntitySearchService.search(nonEmptyEntities, input, postFilters, sortCriterion, from, size, searchFlags, facets); if (facets == null || facets.contains("entity") || facets.contains("_entityType")) { Optional entityTypeAgg = result.getMetadata().getAggregations().stream().filter( @@ -145,6 +138,18 @@ public SearchResult searchAcrossEntities(@Nonnull List entities, @Nonnul return result; } + private List getEntitiesToSearch(@Nonnull List inputEntities) { + List nonEmptyEntities; + List lowercaseEntities = inputEntities.stream().map(String::toLowerCase).collect(Collectors.toList()); + try (Timer.Context ignored = MetricUtils.timer(this.getClass(), "getNonEmptyEntities").time()) { + nonEmptyEntities = _entityDocCountCache.getNonEmptyEntities(); + } + if (!inputEntities.isEmpty()) { + nonEmptyEntities = nonEmptyEntities.stream().filter(lowercaseEntities::contains).collect(Collectors.toList()); + } + return nonEmptyEntities; + } + /** * Gets a list of documents that match given search request across multiple entities. The results are aggregated and filters are applied to the * search hits and not the aggregation results. @@ -165,6 +170,6 @@ public ScrollResult scrollAcrossEntities(@Nonnull List entities, @Nonnul log.debug(String.format( "Searching Search documents entities: %s, input: %s, postFilters: %s, sortCriterion: %s, from: %s, size: %s", entities, input, postFilters, sortCriterion, scrollId, size)); - return _cachingEntitySearchService.scroll(entities, input, postFilters, sortCriterion, scrollId, keepAlive, size, searchFlags); + return _cachingEntitySearchService.scroll(getEntitiesToSearch(entities), input, postFilters, sortCriterion, scrollId, keepAlive, size, searchFlags); } }