我使用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。当我例如用
elasticsearch在内容中仅返回5个数据,但在计数26个数据中显示
数据未按安装排序。我真的不知道该如何纠正这种行为。
提前致谢。
最佳答案
我在屏幕快照的apkList.content
列表中看到了6个元素。因为这是第1页,页面大小为20,并且元素总数为26,所以这是正确的。
要获得前20个,您将获得大小为20的第0页。