Commit 97d68f96eb6ef00dd274a9f80516926599122d3a
1 parent
befba2bb
Entity Data Query Improvements for SearchText
Showing
1 changed file
with
10 additions
and
19 deletions
... | ... | @@ -130,7 +130,8 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
130 | 130 | |
131 | 131 | String entityWhereClause = this.buildEntityWhere(ctx, tenantId, customerId, query.getEntityFilter(), entityFieldsFiltersMapping, entityType); |
132 | 132 | String latestJoins = EntityKeyMapping.buildLatestJoins(ctx, query.getEntityFilter(), entityType, allLatestMappings); |
133 | - String whereClause = this.buildWhere(ctx, selectionMapping, latestFiltersMapping, pageLink.getTextSearch()); | |
133 | + String whereClause = this.buildWhere(ctx, latestFiltersMapping); | |
134 | + String textSearchQuery = this.buildTextSearchQuery(ctx, selectionMapping, pageLink.getTextSearch()); | |
134 | 135 | String entityFieldsSelection = EntityKeyMapping.buildSelections(entityFieldsSelectionMapping); |
135 | 136 | String entityTypeStr; |
136 | 137 | if (query.getEntityFilter().getType().equals(EntityFilterType.RELATIONS_QUERY)) { |
... | ... | @@ -149,14 +150,14 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
149 | 150 | topSelection = topSelection + ", " + latestSelection; |
150 | 151 | } |
151 | 152 | |
152 | - String fromClause = String.format("from (select %s from (select %s from %s e where %s) entities %s %s) result", | |
153 | + String fromClause = String.format("from (select %s from (select %s from %s e where %s) entities %s %s) result %s", | |
153 | 154 | topSelection, |
154 | 155 | entityFieldsSelection, |
155 | 156 | addEntityTableQuery(ctx, query.getEntityFilter(), entityType), |
156 | 157 | entityWhereClause, |
157 | 158 | latestJoins, |
158 | - whereClause); | |
159 | - | |
159 | + whereClause, | |
160 | + textSearchQuery); | |
160 | 161 | |
161 | 162 | int totalElements = jdbcTemplate.queryForObject(String.format("select count(*) %s", fromClause), ctx, Integer.class); |
162 | 163 | |
... | ... | @@ -435,19 +436,10 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
435 | 436 | " END as label"; |
436 | 437 | } |
437 | 438 | |
438 | - private String buildWhere(EntityQueryContext ctx, List<EntityKeyMapping> selectionMapping, List<EntityKeyMapping> latestFiltersMapping, String searchText) { | |
439 | + private String buildWhere(EntityQueryContext ctx, List<EntityKeyMapping> latestFiltersMapping) { | |
439 | 440 | String latestFilters = EntityKeyMapping.buildQuery(ctx, latestFiltersMapping); |
440 | - String textSearchQuery = this.buildTextSearchQuery(ctx, selectionMapping, searchText); | |
441 | - String query; | |
442 | - if (!StringUtils.isEmpty(latestFilters) && !StringUtils.isEmpty(textSearchQuery)) { | |
443 | - query = String.join(" AND ", latestFilters, textSearchQuery); | |
444 | - } else if (!StringUtils.isEmpty(latestFilters)) { | |
445 | - query = latestFilters; | |
446 | - } else { | |
447 | - query = textSearchQuery; | |
448 | - } | |
449 | - if (!StringUtils.isEmpty(query)) { | |
450 | - return String.format("where %s", query); | |
441 | + if (!StringUtils.isEmpty(latestFilters)) { | |
442 | + return String.format("where %s", latestFilters); | |
451 | 443 | } else { |
452 | 444 | return ""; |
453 | 445 | } |
... | ... | @@ -462,11 +454,10 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
462 | 454 | return String.format("LOWER(%s) LIKE :%s", mapping.getValueAlias(), paramName); |
463 | 455 | } |
464 | 456 | ).collect(Collectors.toList()); |
465 | - return String.format("(%s)", String.join(" or ", searchPredicates)); | |
457 | + return String.format(" WHERE %s", String.join(" or ", searchPredicates)); | |
466 | 458 | } else { |
467 | - return null; | |
459 | + return ""; | |
468 | 460 | } |
469 | - | |
470 | 461 | } |
471 | 462 | |
472 | 463 | private String singleEntityQuery(EntityQueryContext ctx, SingleEntityFilter filter) { | ... | ... |