如何解决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")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。