Skip to content

Commit

Permalink
1447 - Improves the tag search engine once we click on the tag on the…
Browse files Browse the repository at this point in the history
… home page

Added count of used tags for dataset fields to the overall tags counter
  • Loading branch information
Vladysl committed Oct 10, 2023
1 parent b6036a4 commit b35bfc7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import static org.opendatadiscovery.oddplatform.model.Tables.OWNERSHIP;
import static org.opendatadiscovery.oddplatform.model.Tables.SEARCH_ENTRYPOINT;
import static org.opendatadiscovery.oddplatform.model.Tables.TAG;
import static org.opendatadiscovery.oddplatform.model.Tables.TAG_TO_DATASET_FIELD;
import static org.opendatadiscovery.oddplatform.model.Tables.TAG_TO_DATA_ENTITY;
import static org.opendatadiscovery.oddplatform.model.Tables.TITLE;
import static org.opendatadiscovery.oddplatform.repository.util.DataEntityCTEQueryConfig.AGG_METADATA_FIELD;
Expand Down Expand Up @@ -445,7 +444,6 @@ public Mono<Long> countByState(final FacetStateDto state, final OwnerPojo owner)
final var select = DSL.select(countDistinct(DATA_ENTITY.ID))
.from(DATA_ENTITY)
.join(SEARCH_ENTRYPOINT).on(SEARCH_ENTRYPOINT.DATA_ENTITY_ID.eq(DATA_ENTITY.ID))
.leftJoin(TAG_TO_DATA_ENTITY).on(TAG_TO_DATA_ENTITY.DATA_ENTITY_ID.eq(DATA_ENTITY.ID))
.leftJoin(DATASET_VERSION)
.on(DATASET_VERSION.DATASET_ODDRN.eq(DATA_ENTITY.ODDRN))
.leftJoin(DATA_SOURCE).on(DATA_SOURCE.ID.eq(DATA_ENTITY.DATA_SOURCE_ID))
Expand Down Expand Up @@ -681,8 +679,6 @@ public Mono<List<DataEntityDimensionsDto>> findByState(final FacetStateDto state
.on(DATA_SOURCE.ID.eq(jooqQueryHelper.getField(deCte, DATA_ENTITY.DATA_SOURCE_ID)))
.leftJoin(NAMESPACE).on(NAMESPACE.ID.eq(jooqQueryHelper.getField(deCte, DATA_ENTITY.NAMESPACE_ID)))
.or(NAMESPACE.ID.eq(DATA_SOURCE.NAMESPACE_ID))
.leftJoin(TAG_TO_DATA_ENTITY)
.on(TAG_TO_DATA_ENTITY.DATA_ENTITY_ID.eq(jooqQueryHelper.getField(deCte, DATA_ENTITY.ID)))
.leftJoin(DATASET_VERSION)
.on(DATASET_VERSION.DATASET_ODDRN.eq(jooqQueryHelper.getField(deCte, DATA_ENTITY.ODDRN)))
.leftJoin(OWNERSHIP).on(OWNERSHIP.DATA_ENTITY_ID.eq(jooqQueryHelper.getField(deCte, DATA_ENTITY.ID)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Mono<Page<TagDto>> listMostPopular(final String query, final List<Long> i
paginate(homogeneousQuery, List.of(new OrderByField(TAG.ID, SortOrder.ASC)), (page - 1) * size, size);

final Table<? extends Record> tagCte = select.asTable("tag_cte");
Table<Record> unionUsages = getDataEntityWithDatasetFields(tagCte, select);
final Table<Record> unionUsages = getDataEntityWithDatasetFields(tagCte, select);

final var cteSelect = DSL.select(unionUsages.fields(tagCte.fields()))
.select(DSL.boolOr(unionUsages.field(EXTERNAL_FIELD, Boolean.class)).as(EXTERNAL_FIELD))
Expand Down Expand Up @@ -370,7 +370,8 @@ public Flux<TagToDatasetFieldPojo> createDatasetFieldRelations(final Collection<
return jooqReactiveOperations.flux(query).map(r -> r.into(TagToDatasetFieldPojo.class));
}

private static Table<Record> getDataEntityWithDatasetFields(Table<? extends Record> tagCte, Select<? extends Record> select) {
private static Table<Record> getDataEntityWithDatasetFields(final Table<? extends Record> tagCte,
final Select<? extends Record> select) {
return DSL.with(tagCte.getName())
.as(select)
.select(tagCte.fields())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,30 @@ public class FTSConstants {
FacetType.NAMESPACES, filters -> NAMESPACE.ID.in(extractFilterId(filters)),
FacetType.TYPES, filters -> DATA_ENTITY.TYPE_ID.in(extractFilterId(filters)),
FacetType.OWNERS, filters -> OWNER.ID.in(extractFilterId(filters)),
FacetType.TAGS, filters -> TAG_TO_DATA_ENTITY.TAG_ID.in(extractFilterId(filters))
.or(DATASET_VERSION.ID.in(select(DATASET_STRUCTURE.DATASET_VERSION_ID)
.from(DATASET_STRUCTURE)
.join(DATASET_FIELD)
.on(DATASET_FIELD.ID.eq(DATASET_STRUCTURE.DATASET_FIELD_ID))
.join(TAG_TO_DATASET_FIELD)
.on(TAG_TO_DATASET_FIELD.TAG_ID.in(extractFilterId(filters))
.and(TAG_TO_DATASET_FIELD.DATASET_FIELD_ID.eq(DATASET_FIELD.ID)))
.where(DATASET_STRUCTURE.DATASET_VERSION_ID.in(
select(DSL.max(DATASET_VERSION.ID))
.from(DATASET_VERSION)
.groupBy(DATASET_VERSION.DATASET_ODDRN)))
)),
FacetType.TAGS, filters -> {
final var dataEntities = DSL.select(DATASET_VERSION.DATASET_ODDRN)
.from(TAG_TO_DATA_ENTITY, DATA_ENTITY, DATASET_VERSION)
.where(TAG_TO_DATA_ENTITY.TAG_ID.in(extractFilterId(filters)))
.and(TAG_TO_DATA_ENTITY.DATA_ENTITY_ID.eq(DATA_ENTITY.ID))
.and(DATA_ENTITY.ODDRN.eq(DATASET_VERSION.DATASET_ODDRN))
.union(DSL.select(DATASET_VERSION.DATASET_ODDRN)
.from(DATASET_VERSION)
.where(DATASET_VERSION.ID.in(
select(DATASET_STRUCTURE.DATASET_VERSION_ID)
.from(DATASET_STRUCTURE, DATASET_FIELD, TAG_TO_DATASET_FIELD)
.where(DATASET_STRUCTURE.DATASET_VERSION_ID.in(
select(DSL.max(DATASET_VERSION.ID))
.from(DATASET_VERSION)
.groupBy(DATASET_VERSION.DATASET_ODDRN)))
.and(DATASET_FIELD.ID.eq(DATASET_STRUCTURE.DATASET_FIELD_ID))
.and(TAG_TO_DATASET_FIELD.DATASET_FIELD_ID.eq(DATASET_FIELD.ID))
.and(TAG_TO_DATASET_FIELD.TAG_ID.in(extractFilterId(filters)))
)
)
);

return DATASET_VERSION.DATASET_ODDRN.in(dataEntities);
},
FacetType.GROUPS, filters -> {
final var groupOddrns = DSL.select(DATA_ENTITY.ODDRN)
.from(DATA_ENTITY)
Expand Down

0 comments on commit b35bfc7

Please sign in to comment.