|
11 | 11 | import com.linkedin.common.urn.Urn;
|
12 | 12 | import com.linkedin.common.urn.UrnUtils;
|
13 | 13 | import com.linkedin.datahub.graphql.QueryContext;
|
| 14 | +import com.linkedin.datahub.graphql.generated.AutoCompleteResults; |
14 | 15 | import com.linkedin.datahub.graphql.generated.Entity;
|
15 | 16 | import com.linkedin.datahub.graphql.generated.EntityType;
|
| 17 | +import com.linkedin.datahub.graphql.generated.FacetFilterInput; |
16 | 18 | import com.linkedin.datahub.graphql.generated.GlossaryNode;
|
| 19 | +import com.linkedin.datahub.graphql.generated.SearchResults; |
| 20 | +import com.linkedin.datahub.graphql.resolvers.ResolverUtils; |
| 21 | +import com.linkedin.datahub.graphql.types.SearchableEntityType; |
17 | 22 | import com.linkedin.datahub.graphql.types.glossary.mappers.GlossaryNodeMapper;
|
| 23 | +import com.linkedin.datahub.graphql.types.mappers.AutoCompleteResultsMapper; |
| 24 | +import com.linkedin.datahub.graphql.types.mappers.UrnSearchResultsMapper; |
18 | 25 | import com.linkedin.entity.EntityResponse;
|
19 | 26 | import com.linkedin.entity.client.EntityClient;
|
| 27 | +import com.linkedin.metadata.query.AutoCompleteResult; |
| 28 | +import com.linkedin.metadata.query.filter.Filter; |
| 29 | +import com.linkedin.metadata.search.SearchResult; |
20 | 30 | import graphql.execution.DataFetcherResult;
|
21 | 31 | import java.util.ArrayList;
|
22 | 32 | import java.util.HashSet;
|
|
25 | 35 | import java.util.Set;
|
26 | 36 | import java.util.function.Function;
|
27 | 37 | import java.util.stream.Collectors;
|
| 38 | +import javax.annotation.Nonnull; |
| 39 | +import javax.annotation.Nullable; |
28 | 40 |
|
29 | 41 | public class GlossaryNodeType
|
30 |
| - implements com.linkedin.datahub.graphql.types.EntityType<GlossaryNode, String> { |
| 42 | + implements SearchableEntityType<GlossaryNode, String>, |
| 43 | + com.linkedin.datahub.graphql.types.EntityType<GlossaryNode, String> { |
31 | 44 |
|
32 | 45 | static final Set<String> ASPECTS_TO_RESOLVE =
|
33 | 46 | ImmutableSet.of(
|
@@ -89,4 +102,39 @@ public List<DataFetcherResult<GlossaryNode>> batchLoad(
|
89 | 102 | throw new RuntimeException("Failed to batch load GlossaryNodes", e);
|
90 | 103 | }
|
91 | 104 | }
|
| 105 | + |
| 106 | + @Override |
| 107 | + public SearchResults search( |
| 108 | + @Nonnull String query, |
| 109 | + @Nullable List<FacetFilterInput> filters, |
| 110 | + int start, |
| 111 | + int count, |
| 112 | + @Nonnull final QueryContext context) |
| 113 | + throws Exception { |
| 114 | + final Map<String, String> facetFilters = |
| 115 | + ResolverUtils.buildFacetFilters(filters, ImmutableSet.of()); |
| 116 | + final SearchResult searchResult = |
| 117 | + _entityClient.search( |
| 118 | + context.getOperationContext().withSearchFlags(flags -> flags.setFulltext(true)), |
| 119 | + GLOSSARY_NODE_ENTITY_NAME, |
| 120 | + query, |
| 121 | + facetFilters, |
| 122 | + start, |
| 123 | + count); |
| 124 | + return UrnSearchResultsMapper.map(context, searchResult); |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public AutoCompleteResults autoComplete( |
| 129 | + @Nonnull String query, |
| 130 | + @Nullable String field, |
| 131 | + @Nullable Filter filters, |
| 132 | + int limit, |
| 133 | + @Nonnull final QueryContext context) |
| 134 | + throws Exception { |
| 135 | + final AutoCompleteResult result = |
| 136 | + _entityClient.autoComplete( |
| 137 | + context.getOperationContext(), GLOSSARY_NODE_ENTITY_NAME, query, filters, limit); |
| 138 | + return AutoCompleteResultsMapper.map(context, result); |
| 139 | + } |
92 | 140 | }
|
0 commit comments