diff --git a/boot/platform/src/main/java/com/plate/boot/commons/base/AbstractEntity.java b/boot/platform/src/main/java/com/plate/boot/commons/base/AbstractEntity.java index a1a7ff44..35616d93 100644 --- a/boot/platform/src/main/java/com/plate/boot/commons/base/AbstractEntity.java +++ b/boot/platform/src/main/java/com/plate/boot/commons/base/AbstractEntity.java @@ -80,6 +80,11 @@ public abstract class AbstractEntity implements BaseEntity { @InsertOnlyProperty protected LocalDateTime createdTime; + /** + * Data full text search entity sort + */ + protected Double rank; + /** * Support query for json column */ diff --git a/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryFragment.java b/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryFragment.java index 406d0eb0..0590b4ca 100644 --- a/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryFragment.java +++ b/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryFragment.java @@ -1,5 +1,6 @@ package com.plate.boot.commons.utils.query; +import com.google.common.base.CaseFormat; import com.plate.boot.commons.exception.QueryException; import lombok.Getter; @@ -182,6 +183,16 @@ public QueryFragment limit(int size, long offset) { return this; } + public QueryFragment ts(String column, Object value) { + String lowerCamelCol = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, column); + String queryTable = "ts_" + lowerCamelCol; + columns("TS_RANK_CD(" + lowerCamelCol + ", " + queryTable + ") AS rank"); + query(",TO_TSQUERY('chinese',:" + column + ") AS " + queryTable); + where(queryTable + " @@ " + lowerCamelCol); + put(column, value); + return this; + } + public String whereSql() { if (this.where.length() > 0) { return " WHERE " + this.where; diff --git a/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryHelper.java b/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryHelper.java index 1e87a4a8..32a4d5fc 100644 --- a/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryHelper.java +++ b/boot/platform/src/main/java/com/plate/boot/commons/utils/query/QueryHelper.java @@ -271,12 +271,8 @@ private static void processSecurityCodeKey(QueryFragment queryFragment, Map objectMap, String prefix) { if (objectMap.containsKey("search") && !ObjectUtils.isEmpty(objectMap.get("search"))) { - var textSearch = (String) objectMap.get("search"); var column = StringUtils.hasLength(prefix) ? prefix + ".text_search" : "text_search"; - queryFragment.columns("TS_RANK_CD(" + column + ", queryTextSearch) AS rank"); - queryFragment.query(",TO_TSQUERY('chinese',:textSearch) queryTextSearch"); - queryFragment.where(column + "@@TO_TSQUERY('chinese',:textSearch)"); - queryFragment.put("textSearch", textSearch); + queryFragment.ts(column, objectMap.get("search")); } }