Micronaut数据分页全文搜索查询

问题描述

我正在使用Micronaut Data版本1.0.2。

给出以下JPA实体类:

pil_image = Image.fromarray(test_image)

我可以使用以下@Entity public class Product { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String code; private String name; private String fullName; } 方法创建全文搜索查询:

PageableRepository

但是,我在为@Repository public interface ProductRepository extends PageableRepository<Product,Long> { Slice<Product> findByCodeLikeOrNameLikeOrFullNameLike( String code,String name,String fullName,Pageable pageable); } 属性添加另一个条件时遇到问题。我要实现的等同于以下SQL:

name

我测试了以下方法:

select * from product
where code like '%search%' 
or (name like '%search%' and name not like '%-%')
or full_name like '%search%'

有什么想法使它起作用吗?

非常感谢。

解决方法

如果您使用@Query,则应该类似于:

@Query(value = "select p from Product p where (p.code like :code or p.fullName like :fullName or p.name like :name) and p.name not like :ignoreName") 
Slice<Product> fullSearch(String code,String name,String ignoreName,String fullName,Pageable pageable);

在这里您可以省略countQuery,因为使用Slice<Product>

如果要使用Page<Product>,则需要提供元素总数。因此,您需要提供计数查询。

喜欢:

countQuery = "select count(p.id) from Product p where (p.code like :code or p.fullName like :fullName or p.name like :name) and p.name not like :ignoreName")

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...