gpt4 book ai didi

java - Elasticsearch存储库分页未返回正确的页面大小并且未对数据进行排序

转载 作者:行者123 更新时间:2023-12-03 01:13:34 24 4
gpt4 key购买 nike

我使用spring 2.2和spring flex 搜索3.2.4。
我有这种方法可以在 flex 搜索中找到所有类别为“游戏”或“应用程序”的apk,并按安装数量对其进行排序。

public ResponseList<Apk> findMostDownloadedApkByCategory(String categoryName, int page, int size) {

logger.info("find most downloaded Apk By Category");
List<ApkDto>apkDtoList = new ArrayList<>();
ResponseList<Apk> responseList = new ResponseList(apkDtoList, false, page);
Page<Apk> apkList = apkRepo.findByCategoryNameIgnoreCaseOrderByInstallsDesc(categoryName, PageRequest.of(page, size));

if(!apkList.isEmpty()) {

ApkDto apkDto = null;
//iterate over each element
for(Apk apk : apkList) {

System.out.println(apk.getInstalls());
//We complete the dto with the company if the company exist
Optional<Company> companyOpt = companyService.findById(apk.getCompanyId());

if(companyOpt.isPresent()) {
Company company = companyOpt.get();
CompanyDto companyDto = new CompanyDto(apk.getCompanyId(), company.getName(), company.getDescription(), company.getAdress(), company.getCountry());
//convert the apk to apk dto, add the company
apkDto = convertApkToDto(apk, companyDto);
apkDtoList.add(apkDto);
}

}
responseList = new ResponseList(apkDtoList, apkList.hasNext(), page);
}
return responseList;
}
我的资料库:
Page<Apk> findByCategoryNameIgnoreCaseOrderByInstallsDesc(String categoryName, Pageable pageable);
在我的 flex 搜索中,我有26个带有类别“Game”的数据,并且安装范围是0到56。
当我例如用

page = 1 and size = 20


elasticsearch在内容中仅返回5个数据,但在计数26个数据中显示
enter image description here
数据未按安装排序。我真的不知道该如何纠正这种行为。
提前致谢。

最佳答案

我在屏幕快照的apkList.content列表中看到了6个元素。因为这是第1页,页面大小为20,并且元素总数为26,所以这是正确的。
要获得前20个,您将获得大小为20的第0页。

关于java - Elasticsearch存储库分页未返回正确的页面大小并且未对数据进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63428027/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com