|
|
@ -5,6 +5,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.dto.mapper.JournalMapper;
|
|
|
|
import com.luoo.music.dto.mapper.JournalMapper;
|
|
|
|
import com.luoo.music.dto.mapper.SongMapper;
|
|
|
|
import com.luoo.music.dto.mapper.SongMapper;
|
|
|
|
|
|
|
|
import com.luoo.music.dto.request.AutoCompleteReq;
|
|
|
|
import com.luoo.music.dto.response.SearchCategoryDTO;
|
|
|
|
import com.luoo.music.dto.response.SearchCategoryDTO;
|
|
|
|
import com.luoo.music.dto.response.SearchResultDTO;
|
|
|
|
import com.luoo.music.dto.response.SearchResultDTO;
|
|
|
|
import io.swagger.annotations.*;
|
|
|
|
import io.swagger.annotations.*;
|
|
|
@ -35,6 +36,7 @@ import constants.Constants;
|
|
|
|
@Api(tags = "雀跃APP搜索 APIs")
|
|
|
|
@Api(tags = "雀跃APP搜索 APIs")
|
|
|
|
@RequestMapping("/search")
|
|
|
|
@RequestMapping("/search")
|
|
|
|
public class SearchController {
|
|
|
|
public class SearchController {
|
|
|
|
|
|
|
|
private static final int DEFAULT_AUTO_COMPLETE_LIMIT = 10;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private JournalService journalService;
|
|
|
|
private JournalService journalService;
|
|
|
|
|
|
|
|
|
|
|
@ -67,25 +69,30 @@ public class SearchController {
|
|
|
|
SearchResultDTO searchResultDTO = new SearchResultDTO();
|
|
|
|
SearchResultDTO searchResultDTO = new SearchResultDTO();
|
|
|
|
List<Journal> journals = journalService.fuzzySearch(keyword);
|
|
|
|
List<Journal> journals = journalService.fuzzySearch(keyword);
|
|
|
|
List<JournalSong> songs = journalSongService.fuzzySearch(keyword);
|
|
|
|
List<JournalSong> songs = journalSongService.fuzzySearch(keyword);
|
|
|
|
searchResultDTO.setJournals(journals.stream().map(j->JournalMapper.getJournalRespDTO(j)).collect(Collectors.toList()));
|
|
|
|
searchResultDTO.setJournals(
|
|
|
|
|
|
|
|
journals.stream().map(j -> JournalMapper.getJournalRespDTO(j)).collect(Collectors.toList()));
|
|
|
|
searchResultDTO.setSongs(songs.stream().map(SongMapper::getSongRespDTO).collect(Collectors.toList()));
|
|
|
|
searchResultDTO.setSongs(songs.stream().map(SongMapper::getSongRespDTO).collect(Collectors.toList()));
|
|
|
|
return Result.success(searchResultDTO);
|
|
|
|
return Result.success(searchResultDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "3.搜索自动补全")
|
|
|
|
@ApiOperation(value = "3.搜索自动补全", notes = "limit 默认查10条")
|
|
|
|
@ApiImplicitParams({ @ApiImplicitParam(name = "query", value = "搜索词", required = true) })
|
|
|
|
@GetMapping("/autoComplete")
|
|
|
|
@GetMapping("/autoComplete/{query}")
|
|
|
|
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
public Result<List<String>> autoComplete(
|
|
|
|
public Result<List<String>> autoComplete(
|
|
|
|
@RequestHeader(value = "Authorization", required = true) String authorization,
|
|
|
|
@RequestHeader(value = "Authorization", required = true) String authorization,
|
|
|
|
@PathVariable @VerifyParam(required = true) String query) {
|
|
|
|
@VerifyParam(required = true) AutoCompleteReq query) {
|
|
|
|
return Result.success(searchService.autoComplete(query));
|
|
|
|
int limit = getLimit(query.getLimit());
|
|
|
|
|
|
|
|
return Result.success(searchService.autoComplete(query.getQuery(), limit));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getLimit(Integer limit) {
|
|
|
|
|
|
|
|
return null == limit || 0 == limit ? DEFAULT_AUTO_COMPLETE_LIMIT : limit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SearchCategoryDTO getSearchCategoryDTO(Tag tag) {
|
|
|
|
private SearchCategoryDTO getSearchCategoryDTO(Tag tag) {
|
|
|
|
SearchCategoryDTO searchCategoryDTO = new SearchCategoryDTO();
|
|
|
|
SearchCategoryDTO searchCategoryDTO = new SearchCategoryDTO();
|
|
|
|
BeanUtils.copyProperties(tag, searchCategoryDTO);
|
|
|
|
BeanUtils.copyProperties(tag, searchCategoryDTO);
|
|
|
|
searchCategoryDTO.setImage(Constants.TAG_RESOURCE_PREFIX+tag.getImage());
|
|
|
|
searchCategoryDTO.setImage(Constants.TAG_RESOURCE_PREFIX + tag.getImage());
|
|
|
|
return searchCategoryDTO;
|
|
|
|
return searchCategoryDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|