From b35bfc733033f149c6e3251b581a1651d23a6f6c Mon Sep 17 00:00:00 2001 From: vburlachenko Date: Tue, 10 Oct 2023 17:58:21 +0300 Subject: [PATCH] 1447 - Improves the tag search engine once we click on the tag on the home page Added count of used tags for dataset fields to the overall tags counter --- .../ReactiveDataEntityRepositoryImpl.java | 4 -- .../reactive/ReactiveTagRepositoryImpl.java | 5 ++- .../repository/util/FTSConstants.java | 37 ++++++++++++------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveDataEntityRepositoryImpl.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveDataEntityRepositoryImpl.java index 924f7ccae..1fcd92b1a 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveDataEntityRepositoryImpl.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveDataEntityRepositoryImpl.java @@ -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; @@ -445,7 +444,6 @@ public Mono 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)) @@ -681,8 +679,6 @@ public Mono> 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))) diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTagRepositoryImpl.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTagRepositoryImpl.java index 94b7d8d7f..42d750dde 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTagRepositoryImpl.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveTagRepositoryImpl.java @@ -148,7 +148,7 @@ public Mono> listMostPopular(final String query, final List i paginate(homogeneousQuery, List.of(new OrderByField(TAG.ID, SortOrder.ASC)), (page - 1) * size, size); final Table tagCte = select.asTable("tag_cte"); - Table unionUsages = getDataEntityWithDatasetFields(tagCte, select); + final Table 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)) @@ -370,7 +370,8 @@ public Flux createDatasetFieldRelations(final Collection< return jooqReactiveOperations.flux(query).map(r -> r.into(TagToDatasetFieldPojo.class)); } - private static Table getDataEntityWithDatasetFields(Table tagCte, Select select) { + private static Table getDataEntityWithDatasetFields(final Table tagCte, + final Select select) { return DSL.with(tagCte.getName()) .as(select) .select(tagCte.fields()) diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/util/FTSConstants.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/util/FTSConstants.java index 144d3f0e2..f787adcd9 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/util/FTSConstants.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/util/FTSConstants.java @@ -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)