排序
排序比较简单,将上面的方法改造一下,加入排序:
@Override
public ScoredPage<Music> searchByNameProjection(String searchName, long pageIndex, int pageSize) {
String[] words = searchName.toUpperCase().split(" ");
String[] contidionFields = new String[]{Music.FIELD_SONG_NAME, Music.FIELD_SINGER_NAME};
Criteria conditions = createSearchConditions(contidionFields, words);
SimpleQuery search = new SimpleQuery(conditions);
Sort sort = new Sort(Sort.Direction.DESC, Music.FIELD_SONG_ID);
search.addSort(sort);
search.addProjectionOnField(Music.FIELD_SONG_NAME);
search.setOffset(pageIndex);
search.setRows(pageSize);
ScoredPage<Music> page = solrTemplate.queryForPage(Music.CORE_NAME, search, Music.class);
return page;
}
执行上面代码,返回结果即会按照songId 倒序排列。 |