通过在每个持久存储上保存搜索字符串并更新到数据库来解决此问题。首先为searchString创建一列:
@Column(name = "SEARCH_STRING", length = 1000) private String searchString;
存储很便宜,DB上的开销并不大。
然后保存更新并继续:
@PreUpdate @PrePersist void updateSearchString() { final String fullSearchString = StringUtils.join(Arrays.asList( login, firstName, lastName, email, Boolean.TRUE.equals(active) ? "tak" : "nie", profile.getDescription()), " "); this.searchString = StringUtils.substring(fullSearchString, 0, 999); }然后我可以使用以下常规JPQL查询
LIKE:
SELECT u FROM User u WHERe u.searchString LIKE '%' || :text || '%'
或使用示例查询:
ExampleMatcher matcher = ExampleMatcher.matching(). withMatcher("searchString", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.CONTAINING).ignoreCase());


