Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(filters) Fix autocomplete for platforms and improve advanced search builder #12560

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,38 @@

import static com.linkedin.metadata.Constants.*;

import com.google.common.collect.ImmutableSet;
import com.linkedin.common.urn.Urn;
import com.linkedin.common.urn.UrnUtils;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.generated.AutoCompleteResults;
import com.linkedin.datahub.graphql.generated.DataPlatform;
import com.linkedin.datahub.graphql.generated.Entity;
import com.linkedin.datahub.graphql.generated.FacetFilterInput;
import com.linkedin.datahub.graphql.generated.SearchResults;
import com.linkedin.datahub.graphql.resolvers.ResolverUtils;
import com.linkedin.datahub.graphql.types.EntityType;
import com.linkedin.datahub.graphql.types.SearchableEntityType;
import com.linkedin.datahub.graphql.types.dataplatform.mappers.DataPlatformMapper;
import com.linkedin.datahub.graphql.types.mappers.AutoCompleteResultsMapper;
import com.linkedin.datahub.graphql.types.mappers.UrnSearchResultsMapper;
import com.linkedin.entity.EntityResponse;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.metadata.query.AutoCompleteResult;
import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.search.SearchResult;
import graphql.execution.DataFetcherResult;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class DataPlatformType implements EntityType<DataPlatform, String> {
public class DataPlatformType
implements SearchableEntityType<DataPlatform, String>, EntityType<DataPlatform, String> {

private final EntityClient _entityClient;

Expand Down Expand Up @@ -75,4 +89,39 @@ public com.linkedin.datahub.graphql.generated.EntityType type() {
public Function<Entity, String> getKeyProvider() {
return Entity::getUrn;
}

@Override
public SearchResults search(
@Nonnull String query,
@Nullable List<FacetFilterInput> filters,
int start,
int count,
@Nonnull final QueryContext context)
throws Exception {
final Map<String, String> facetFilters =
ResolverUtils.buildFacetFilters(filters, ImmutableSet.of());
final SearchResult searchResult =
_entityClient.search(
context.getOperationContext().withSearchFlags(flags -> flags.setFulltext(true)),
DATA_PLATFORM_ENTITY_NAME,
query,
facetFilters,
start,
count);
return UrnSearchResultsMapper.map(context, searchResult);
}

@Override
public AutoCompleteResults autoComplete(
@Nonnull String query,
@Nullable String field,
@Nullable Filter filters,
int limit,
@Nonnull final QueryContext context)
throws Exception {
final AutoCompleteResult result =
_entityClient.autoComplete(
context.getOperationContext(), DATA_PLATFORM_ENTITY_NAME, query, filters, limit);
return AutoCompleteResultsMapper.map(context, result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
className,
}: Props) {
const entityRegistry = useEntityRegistry();
const isSearchable =
field.entityTypes?.length && field.entityTypes.every((t) => entityRegistry.getEntity(t).isSearchEnabled());
const isSearchable = !!field.entityTypes?.length;

Check warning on line 31 in datahub-web-react/src/app/searchV2/filters/value/EntityValueMenu.tsx

View check run for this annotation

Codecov / codecov/patch

datahub-web-react/src/app/searchV2/filters/value/EntityValueMenu.tsx#L31

Added line #L31 was not covered by tests
const { displayName } = field;

// Ideally we would not have staged values, and filters would update automatically.
Expand All @@ -43,7 +42,8 @@
const finalSearchOptions = [...localSearchOptions, ...deduplicateOptions(localSearchOptions, searchOptions)];

// Compute the final options to show to the user.
const finalOptions = searchQuery ? finalSearchOptions : defaultOptions;
const finalDefaultOptions = defaultOptions.length ? defaultOptions : searchOptions;
const finalOptions = searchQuery ? finalSearchOptions : finalDefaultOptions;

Check warning on line 46 in datahub-web-react/src/app/searchV2/filters/value/EntityValueMenu.tsx

View check run for this annotation

Codecov / codecov/patch

datahub-web-react/src/app/searchV2/filters/value/EntityValueMenu.tsx#L45-L46

Added lines #L45 - L46 were not covered by tests

// Finally, create the option set.
// TODO: Add an option set for "no x".
Expand Down
22 changes: 21 additions & 1 deletion datahub-web-react/src/app/searchV2/filters/value/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import {
useAggregateAcrossEntitiesQuery,
useGetAutoCompleteMultipleResultsQuery,
useGetSearchResultsForMultipleQuery,
} from '../../../../graphql/search.generated';
import { EntityType } from '../../../../types.generated';
import { capitalizeFirstLetterOnly } from '../../../shared/textUtil';
Expand Down Expand Up @@ -94,6 +95,19 @@
fetchPolicy: 'cache-first',
});

// do initial search to get initial data to display
const { data: searchData, loading: searchLoading } = useGetSearchResultsForMultipleQuery({
skip: skip || !!query, // only do a search if not doing auto-complete,
variables: {
input: {
query: '*',
types: field.entityTypes,
count: 10,
},
},
fetchPolicy: 'cache-first',
});

Check warning on line 110 in datahub-web-react/src/app/searchV2/filters/value/utils.tsx

View check run for this annotation

Codecov / codecov/patch

datahub-web-react/src/app/searchV2/filters/value/utils.tsx#L98-L110

Added lines #L98 - L110 were not covered by tests
if (skip) {
return { loading: false, options: [] };
}
Expand All @@ -107,7 +121,13 @@
icon: field.icon,
};
});
return { options: options || [], loading };
const searchOptions = searchData?.searchAcrossEntities?.searchResults.map((result) => ({
value: result.entity.urn,
entity: result.entity,
icon: field.icon,
}));

return { options: options || searchOptions || [], loading: loading || searchLoading };

Check warning on line 130 in datahub-web-react/src/app/searchV2/filters/value/utils.tsx

View check run for this annotation

Codecov / codecov/patch

datahub-web-react/src/app/searchV2/filters/value/utils.tsx#L124-L130

Added lines #L124 - L130 were not covered by tests
};

/**
Expand Down
Loading