From f2a4e58eeaa1dab18bf33a102707816296aae3f7 Mon Sep 17 00:00:00 2001 From: Joy A Date: Fri, 12 Apr 2024 17:13:57 +0530 Subject: [PATCH] #96 | Search by Text concepts --- .../etl/dto/ConceptFilterSearch.java | 25 ++++++++++++----- .../etl/repository/MediaTableRepository.java | 28 ++++++++++++------- src/main/resources/sql/api/searchMedia.sql.st | 26 +++++++++-------- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/avniproject/etl/dto/ConceptFilterSearch.java b/src/main/java/org/avniproject/etl/dto/ConceptFilterSearch.java index 21a6f50..8507c08 100644 --- a/src/main/java/org/avniproject/etl/dto/ConceptFilterSearch.java +++ b/src/main/java/org/avniproject/etl/dto/ConceptFilterSearch.java @@ -8,15 +8,17 @@ public class ConceptFilterSearch { private List columnValues; private String from; private String to; - private boolean isNonStringValue; + private boolean nonStringValue; + private boolean exactSearch; - public ConceptFilterSearch(String tableName, String columnName, List columnValues, String from, String to, boolean isNonStringValue) { + public ConceptFilterSearch(String tableName, String columnName, List columnValues, String from, String to, boolean nonStringValue, boolean exactSearch) { this.tableName = tableName; this.columnName = columnName; this.columnValues = columnValues; this.from = from; this.to = to; - this.isNonStringValue = isNonStringValue; + this.nonStringValue = nonStringValue; + this.exactSearch = exactSearch; } public String getTableName() { @@ -51,7 +53,8 @@ public String toString() { ", columnValues=" + columnValues + ", from=" + from + ", to=" + to + - ", isNonStringValue=" + isNonStringValue + + ", nonStringValue=" + nonStringValue + + ", exactSearch=" + exactSearch + '}'; } @@ -71,11 +74,19 @@ public void setTo(String to) { this.to = to; } - public boolean getNonStringValue() { - return isNonStringValue; + public boolean isNonStringValue() { + return nonStringValue; } public void setNonStringValue(boolean nonStringValue) { - isNonStringValue = nonStringValue; + this.nonStringValue = nonStringValue; + } + + public boolean isExactSearch() { + return exactSearch; + } + + public void setExactSearch(boolean exactSearch) { + this.exactSearch = exactSearch; } } diff --git a/src/main/java/org/avniproject/etl/repository/MediaTableRepository.java b/src/main/java/org/avniproject/etl/repository/MediaTableRepository.java index 1f7777b..e618b74 100644 --- a/src/main/java/org/avniproject/etl/repository/MediaTableRepository.java +++ b/src/main/java/org/avniproject/etl/repository/MediaTableRepository.java @@ -39,12 +39,19 @@ public class MediaTableRepository { private List determineConceptFilterTablesAndColumns(List conceptFilters) { logger.debug("searching concepts: " + conceptFilters); List conceptFilterTablesAndColumns = new ArrayList<>(); - List supportedConceptSearchTypes = Arrays.asList( + List textConceptSearchTypes = Arrays.asList( + ColumnMetadata.ConceptType.Text, + ColumnMetadata.ConceptType.Id, + ColumnMetadata.ConceptType.Notes + ); + List supportedConceptSearchTypes = new ArrayList<>(Arrays.asList( ColumnMetadata.ConceptType.Numeric, ColumnMetadata.ConceptType.Date, ColumnMetadata.ConceptType.SingleSelect, ColumnMetadata.ConceptType.MultiSelect - ); + )); + supportedConceptSearchTypes.addAll(textConceptSearchTypes); + SchemaMetadata schema = schemaMetadataRepository.getExistingSchemaMetadata(); List tablesToSearch = Stream.of(schema.getAllSubjectTables(), schema.getAllProgramEnrolmentTables(), @@ -53,9 +60,9 @@ private List determineConceptFilterTablesAndColumns(List column = tableMetadata.getColumnMetadataList() .stream() .filter(columnMetadata -> Objects.equals(columnMetadata.getConceptUuid(), conceptUuid) @@ -66,7 +73,8 @@ private List determineConceptFilterTablesAndColumns(List List searchInternal(MediaSearchRequest mediaSearchRequest, Page p } Query query = new MediaSearchQueryBuilder() - .withPage(page) - .withMediaSearchRequest(mediaSearchRequest) - .withSearchConceptFilters(conceptFilterSearches) - .build(); + .withPage(page) + .withMediaSearchRequest(mediaSearchRequest) + .withSearchConceptFilters(conceptFilterSearches) + .build(); return runInSchemaUserContext(() -> new NamedParameterJdbcTemplate(jdbcTemplate) - .query(query.sql(), query.parameters(), rowMapper), jdbcTemplate); + .query(query.sql(), query.parameters(), rowMapper), jdbcTemplate); } diff --git a/src/main/resources/sql/api/searchMedia.sql.st b/src/main/resources/sql/api/searchMedia.sql.st index 213f49e..99c56e4 100644 --- a/src/main/resources/sql/api/searchMedia.sql.st +++ b/src/main/resources/sql/api/searchMedia.sql.st @@ -23,17 +23,21 @@ SELECT media.id as id, FROM .media media JOIN .address address ON address.id = media.address_id - . _ ON media.entity_id = _.id - AND _."" - - IN ('}; separator="', '">') - - if AND else '' AND '' !> - - BETWEEN '' AND '' - - }; separator="\n"> + . ON media.entity_id = .id + + AND ."" + + IN ('}; separator="', '">') + + if AND else '' AND '' !> + + BETWEEN '' AND '' + + + AND ."" ILIKE '%%'}; separator=" \nAND "> + + }; separator="\n"> where media.image_url is not null and media.is_voided is false