|
|
|
@ -5,6 +5,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.dto.mapper.JournalMapper;
|
|
|
|
|
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.SearchResultDTO;
|
|
|
|
|
import io.swagger.annotations.*;
|
|
|
|
@ -35,6 +36,7 @@ import constants.Constants;
|
|
|
|
|
@Api(tags = "雀跃APP搜索 APIs")
|
|
|
|
|
@RequestMapping("/search")
|
|
|
|
|
public class SearchController {
|
|
|
|
|
private static final int DEFAULT_AUTO_COMPLETE_LIMIT = 10;
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalService journalService;
|
|
|
|
|
|
|
|
|
@ -43,7 +45,7 @@ public class SearchController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SearchService searchService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TagService tagService;
|
|
|
|
|
|
|
|
|
@ -67,25 +69,30 @@ public class SearchController {
|
|
|
|
|
SearchResultDTO searchResultDTO = new SearchResultDTO();
|
|
|
|
|
List<Journal> journals = journalService.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()));
|
|
|
|
|
return Result.success(searchResultDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "3.搜索自动补全")
|
|
|
|
|
@ApiImplicitParams({ @ApiImplicitParam(name = "query", value = "搜索词", required = true) })
|
|
|
|
|
@GetMapping("/autoComplete/{query}")
|
|
|
|
|
@ApiOperation(value = "3.搜索自动补全", notes = "limit 默认查10条")
|
|
|
|
|
@GetMapping("/autoComplete")
|
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
|
public Result<List<String>> autoComplete(
|
|
|
|
|
@RequestHeader(value = "Authorization", required = true) String authorization,
|
|
|
|
|
@PathVariable @VerifyParam(required = true) String query) {
|
|
|
|
|
return Result.success(searchService.autoComplete(query));
|
|
|
|
|
@VerifyParam(required = true) AutoCompleteReq 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) {
|
|
|
|
|
SearchCategoryDTO searchCategoryDTO = new SearchCategoryDTO();
|
|
|
|
|
BeanUtils.copyProperties(tag, searchCategoryDTO);
|
|
|
|
|
searchCategoryDTO.setImage(Constants.TAG_RESOURCE_PREFIX+tag.getImage());
|
|
|
|
|
searchCategoryDTO.setImage(Constants.TAG_RESOURCE_PREFIX + tag.getImage());
|
|
|
|
|
return searchCategoryDTO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|