Add base implementation of new tags search

This commit is contained in:
Dmytro Skarzhynets 2023-10-30 12:27:16 +02:00
parent fd735c3d82
commit 1bf3f6066e
2 changed files with 108 additions and 13 deletions

View File

@ -33,14 +33,29 @@ public interface WidgetTypeInfoRepository extends JpaRepository<WidgetTypeInfoEn
"AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " + "AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " +
"AND (wti.name ILIKE CONCAT('%', :searchText, '%') " + "AND (wti.name ILIKE CONCAT('%', :searchText, '%') " +
"OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " + "OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " +
"OR lower(wti.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:searchText), ' '))))", "OR EXISTS (" +
// "OR to_tsvector(lower(array_to_string(wti.tags, ' '))) @@ to_tsquery(lower(:searchText)))))", "SELECT 1 " +
"FROM unnest(wti.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))",
countQuery = "SELECT count(*) FROM widget_type_info_view wti WHERE wti.tenant_id = :systemTenantId " + countQuery = "SELECT count(*) FROM widget_type_info_view wti WHERE wti.tenant_id = :systemTenantId " +
"AND ((:deprecatedFilterEnabled) IS FALSE OR wti.deprecated = :deprecatedFilter) " + "AND ((:deprecatedFilterEnabled) IS FALSE OR wti.deprecated = :deprecatedFilter) " +
"AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " + "AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " +
"AND (wti.name ILIKE CONCAT('%', :searchText, '%') " + "AND (wti.name ILIKE CONCAT('%', :searchText, '%') " +
"OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " + "OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " +
"OR lower(wti.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:searchText), ' '))))" "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wti.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))"
) )
Page<WidgetTypeInfoEntity> findSystemWidgetTypes(@Param("systemTenantId") UUID systemTenantId, Page<WidgetTypeInfoEntity> findSystemWidgetTypes(@Param("systemTenantId") UUID systemTenantId,
@Param("searchText") String searchText, @Param("searchText") String searchText,
@ -57,13 +72,29 @@ public interface WidgetTypeInfoRepository extends JpaRepository<WidgetTypeInfoEn
"AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " + "AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " +
"AND (wti.name ILIKE CONCAT('%', :searchText, '%') " + "AND (wti.name ILIKE CONCAT('%', :searchText, '%') " +
"OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " + "OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " +
"OR lower(wti.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:searchText), ' '))))", "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wti.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))",
countQuery = "SELECT count(*) FROM widget_type_info_view wti WHERE wti.tenant_id IN (:tenantId, :nullTenantId) " + countQuery = "SELECT count(*) FROM widget_type_info_view wti WHERE wti.tenant_id IN (:tenantId, :nullTenantId) " +
"AND ((:deprecatedFilterEnabled) IS FALSE OR wti.deprecated = :deprecatedFilter) " + "AND ((:deprecatedFilterEnabled) IS FALSE OR wti.deprecated = :deprecatedFilter) " +
"AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " + "AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " +
"AND (wti.name ILIKE CONCAT('%', :searchText, '%') " + "AND (wti.name ILIKE CONCAT('%', :searchText, '%') " +
"OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " + "OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " +
"OR lower(wti.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:searchText), ' '))))" "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wti.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))"
) )
Page<WidgetTypeInfoEntity> findAllTenantWidgetTypesByTenantId(@Param("tenantId") UUID tenantId, Page<WidgetTypeInfoEntity> findAllTenantWidgetTypesByTenantId(@Param("tenantId") UUID tenantId,
@Param("nullTenantId") UUID nullTenantId, @Param("nullTenantId") UUID nullTenantId,
@ -81,13 +112,29 @@ public interface WidgetTypeInfoRepository extends JpaRepository<WidgetTypeInfoEn
"AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " + "AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " +
"AND (wti.name ILIKE CONCAT('%', :searchText, '%') " + "AND (wti.name ILIKE CONCAT('%', :searchText, '%') " +
"OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " + "OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " +
"OR lower(wti.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:searchText), ' '))))", "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wti.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))",
countQuery = "SELECT count(*) FROM widget_type_info_view wti WHERE wti.tenant_id = :tenantId " + countQuery = "SELECT count(*) FROM widget_type_info_view wti WHERE wti.tenant_id = :tenantId " +
"AND ((:deprecatedFilterEnabled) IS FALSE OR wti.deprecated = :deprecatedFilter) " + "AND ((:deprecatedFilterEnabled) IS FALSE OR wti.deprecated = :deprecatedFilter) " +
"AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " + "AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " +
"AND (wti.name ILIKE CONCAT('%', :searchText, '%') " + "AND (wti.name ILIKE CONCAT('%', :searchText, '%') " +
"OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " + "OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " +
"OR lower(wti.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:searchText), ' '))))" "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wti.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))"
) )
Page<WidgetTypeInfoEntity> findTenantWidgetTypesByTenantId(@Param("tenantId") UUID tenantId, Page<WidgetTypeInfoEntity> findTenantWidgetTypesByTenantId(@Param("tenantId") UUID tenantId,
@Param("searchText") String searchText, @Param("searchText") String searchText,
@ -111,7 +158,15 @@ public interface WidgetTypeInfoRepository extends JpaRepository<WidgetTypeInfoEn
"AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " + "AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " +
"AND (wti.name ILIKE CONCAT('%', :searchText, '%') " + "AND (wti.name ILIKE CONCAT('%', :searchText, '%') " +
"OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " + "OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " +
"OR lower(wti.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:searchText), ' ')))) " + "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wti.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
")))) " +
"ORDER BY wbw.widget_type_order", "ORDER BY wbw.widget_type_order",
countQuery = "SELECT count(*) FROM widget_type_info_view wti, widgets_bundle_widget wbw " + countQuery = "SELECT count(*) FROM widget_type_info_view wti, widgets_bundle_widget wbw " +
"WHERE wbw.widgets_bundle_id = :widgetsBundleId " + "WHERE wbw.widgets_bundle_id = :widgetsBundleId " +
@ -120,7 +175,15 @@ public interface WidgetTypeInfoRepository extends JpaRepository<WidgetTypeInfoEn
"AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " + "AND ((:widgetTypesEmpty) IS TRUE OR wti.widget_type IN (:widgetTypes)) " +
"AND (wti.name ILIKE CONCAT('%', :searchText, '%') " + "AND (wti.name ILIKE CONCAT('%', :searchText, '%') " +
"OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " + "OR ((:fullSearch) IS TRUE AND (wti.description ILIKE CONCAT('%', :searchText, '%') " +
"OR lower(wti.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:searchText), ' '))))" "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wti.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))"
) )
Page<WidgetTypeInfoEntity> findWidgetTypesInfosByWidgetsBundleId(@Param("widgetsBundleId") UUID widgetsBundleId, Page<WidgetTypeInfoEntity> findWidgetTypesInfosByWidgetsBundleId(@Param("widgetsBundleId") UUID widgetsBundleId,
@Param("searchText") String searchText, @Param("searchText") String searchText,

View File

@ -46,7 +46,15 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
"WHERE wtd.id = wbw.widget_type_id " + "WHERE wtd.id = wbw.widget_type_id " +
"AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " + "AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " +
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " + "OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))", "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wtd.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))",
countQuery = "SELECT count(*) FROM widgets_bundle wb WHERE wb.tenant_id = :systemTenantId " + countQuery = "SELECT count(*) FROM widgets_bundle wb WHERE wb.tenant_id = :systemTenantId " +
"AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " + "AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " +
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " + "OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
@ -54,7 +62,15 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
"WHERE wtd.id = wbw.widget_type_id " + "WHERE wtd.id = wbw.widget_type_id " +
"AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " + "AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " +
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " + "OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))" "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wtd.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))"
) )
Page<WidgetsBundleEntity> findSystemWidgetsBundlesFullSearch(@Param("systemTenantId") UUID systemTenantId, Page<WidgetsBundleEntity> findSystemWidgetsBundlesFullSearch(@Param("systemTenantId") UUID systemTenantId,
@Param("textSearch") String textSearch, @Param("textSearch") String textSearch,
@ -81,7 +97,15 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
"WHERE wtd.id = wbw.widget_type_id " + "WHERE wtd.id = wbw.widget_type_id " +
"AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " + "AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " +
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " + "OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))", "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wtd.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))",
countQuery = "SELECT count(*) FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantId, :nullTenantId) " + countQuery = "SELECT count(*) FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantId, :nullTenantId) " +
"AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " + "AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " +
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " + "OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
@ -89,7 +113,15 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
"WHERE wtd.id = wbw.widget_type_id " + "WHERE wtd.id = wbw.widget_type_id " +
"AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " + "AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " +
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " + "OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))" "OR EXISTS (" +
"SELECT 1 " +
"FROM unnest(wtd.tags) AS currentTag " +
"WHERE :searchText ILIKE '%' || currentTag || '%' " +
"AND (length(:searchText) = length(currentTag) " +
"OR :searchText ILIKE currentTag || ' %' " +
"OR :searchText ILIKE '% ' || currentTag " +
"OR :searchText ILIKE '% ' || currentTag || ' %')" +
"))))"
) )
Page<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantIdFullSearch(@Param("tenantId") UUID tenantId, Page<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantIdFullSearch(@Param("tenantId") UUID tenantId,
@Param("nullTenantId") UUID nullTenantId, @Param("nullTenantId") UUID nullTenantId,