ES查询时,二次查询评分处理

This commit is contained in:
daihh
2023-03-29 19:23:48 +08:00
parent c4a5e03274
commit 41f1ad4085
4 changed files with 35 additions and 0 deletions

View File

@@ -234,12 +234,28 @@ public class CourseFullTextApi extends ApiBaseController{
PageList<CourseFullText> coursePageList = fullTextSearch.search(ICourseFullTextSearch.DEFAULT_INDEX_NAME,pager.getStartRow(), pager.getPageSize(),paras); PageList<CourseFullText> coursePageList = fullTextSearch.search(ICourseFullTextSearch.DEFAULT_INDEX_NAME,pager.getStartRow(), pager.getPageSize(),paras);
//提取教师信息 //提取教师信息
List<String> ids=new ArrayList<String>(); List<String> ids=new ArrayList<String>();
List<String> cids=new ArrayList<String>();
for(CourseFullText c :coursePageList.getList()) { for(CourseFullText c :coursePageList.getList()) {
ids.add(c.getId()); ids.add(c.getId());
if(c.getSource()==2) {
cids.add(c.getId());
}
}
List<Course> clist=null;
if(!cids.isEmpty()) {
clist=courseService.findStudysScoreByIds(cids);
} }
List<CourseTeacher> teachers = courseService.findTeachersByCourseIds(ids); List<CourseTeacher> teachers = courseService.findTeachersByCourseIds(ids);
//注意对于多个教师的情况,这里只是设置第一个教师 //注意对于多个教师的情况,这里只是设置第一个教师
for(CourseFullText c :coursePageList.getList()) { for(CourseFullText c :coursePageList.getList()) {
if(clist!=null) {
for(Course c2 : clist) {
if(c2.getId().equals(c.getId())) {
c.setScore(c2.getScore());
break;
}
}
}
for(CourseTeacher ct : teachers) { for(CourseTeacher ct : teachers) {
if(ct.getCourseId().equals(c.getId())) { if(ct.getCourseId().equals(c.getId())) {
c.setTeacher(ct.getTeacherName()); c.setTeacher(ct.getTeacherName());

View File

@@ -50,6 +50,12 @@ public class Course extends BaseEntity {
} }
public Course(String id,Integer studys,Float score) {
this.setId(id);
this.studys=studys;
this.score=score;
}
public Course(String id,Integer type,String name,String coverImg, Float score,Integer studys,Integer comments,Integer shares,Integer praises,Integer favorites public Course(String id,Integer type,String name,String coverImg, Float score,Integer studys,Integer comments,Integer shares,Integer praises,Integer favorites
,String forUsers,String value,String summary,LocalDateTime publishTime,Boolean isTop) { ,String forUsers,String value,String summary,LocalDateTime publishTime,Boolean isTop) {
this.setId(id); this.setId(id);

View File

@@ -320,6 +320,13 @@ public interface ICourseService {
* 页面二次查询 * 页面二次查询
* */ * */
List<Course> ids(List<String> ids); List<Course> ids(List<String> ids);
/**
* 查询需要的字段
* @param ids
* @return
*/
List<Course> findStudysScoreByIds(List<String> ids);
/** /**

View File

@@ -1653,6 +1653,12 @@ public class CourseServiceImpl implements ICourseService {
courseDao.updateFieldById(id, field, value); courseDao.updateFieldById(id, field, value);
} }
@Override
public List<Course> findStudysScoreByIds(List<String> ids) {
return courseDao.findListByHql("Select new Course(id,studys,score) from Course where id in(?1)",ids);
}