use of org.libresonic.player.domain.SearchResult in project libresonic by Libresonic.
the class RESTController method search.
@RequestMapping(value = "/rest/search", method = { RequestMethod.GET, RequestMethod.POST })
public void search(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
String any = request.getParameter("any");
String artist = request.getParameter("artist");
String album = request.getParameter("album");
String title = request.getParameter("title");
StringBuilder query = new StringBuilder();
if (any != null) {
query.append(any).append(" ");
}
if (artist != null) {
query.append(artist).append(" ");
}
if (album != null) {
query.append(album).append(" ");
}
if (title != null) {
query.append(title);
}
SearchCriteria criteria = new SearchCriteria();
criteria.setQuery(query.toString().trim());
criteria.setCount(getIntParameter(request, "count", 20));
criteria.setOffset(getIntParameter(request, "offset", 0));
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
SearchResult result = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
org.libresonic.restapi.SearchResult searchResult = new org.libresonic.restapi.SearchResult();
searchResult.setOffset(result.getOffset());
searchResult.setTotalHits(result.getTotalHits());
for (MediaFile mediaFile : result.getMediaFiles()) {
searchResult.getMatch().add(createJaxbChild(player, mediaFile, username));
}
Response res = createResponse();
res.setSearchResult(searchResult);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.SearchResult in project libresonic by Libresonic.
the class RESTController method search3.
@RequestMapping(value = "/rest/search3", method = { RequestMethod.GET, RequestMethod.POST })
public void search3(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
Integer musicFolderId = getIntParameter(request, "musicFolderId");
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
SearchResult3 searchResult = new SearchResult3();
String query = request.getParameter("query");
SearchCriteria criteria = new SearchCriteria();
criteria.setQuery(StringUtils.trimToEmpty(query));
criteria.setCount(getIntParameter(request, "artistCount", 20));
criteria.setOffset(getIntParameter(request, "artistOffset", 0));
SearchResult result = searchService.search(criteria, musicFolders, SearchService.IndexType.ARTIST_ID3);
for (Artist artist : result.getArtists()) {
searchResult.getArtist().add(createJaxbArtist(new ArtistID3(), artist, username));
}
criteria.setCount(getIntParameter(request, "albumCount", 20));
criteria.setOffset(getIntParameter(request, "albumOffset", 0));
result = searchService.search(criteria, musicFolders, SearchService.IndexType.ALBUM_ID3);
for (Album album : result.getAlbums()) {
searchResult.getAlbum().add(createJaxbAlbum(new AlbumID3(), album, username));
}
criteria.setCount(getIntParameter(request, "songCount", 20));
criteria.setOffset(getIntParameter(request, "songOffset", 0));
result = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
for (MediaFile song : result.getMediaFiles()) {
searchResult.getSong().add(createJaxbChild(player, song, username));
}
Response res = createResponse();
res.setSearchResult3(searchResult);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.SearchResult in project libresonic by Libresonic.
the class RESTController method search2.
@RequestMapping(value = "/rest/search2", method = { RequestMethod.GET, RequestMethod.POST })
public void search2(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
Integer musicFolderId = getIntParameter(request, "musicFolderId");
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
SearchResult2 searchResult = new SearchResult2();
String query = request.getParameter("query");
SearchCriteria criteria = new SearchCriteria();
criteria.setQuery(StringUtils.trimToEmpty(query));
criteria.setCount(getIntParameter(request, "artistCount", 20));
criteria.setOffset(getIntParameter(request, "artistOffset", 0));
SearchResult artists = searchService.search(criteria, musicFolders, SearchService.IndexType.ARTIST);
for (MediaFile mediaFile : artists.getMediaFiles()) {
searchResult.getArtist().add(createJaxbArtist(mediaFile, username));
}
criteria.setCount(getIntParameter(request, "albumCount", 20));
criteria.setOffset(getIntParameter(request, "albumOffset", 0));
SearchResult albums = searchService.search(criteria, musicFolders, SearchService.IndexType.ALBUM);
for (MediaFile mediaFile : albums.getMediaFiles()) {
searchResult.getAlbum().add(createJaxbChild(player, mediaFile, username));
}
criteria.setCount(getIntParameter(request, "songCount", 20));
criteria.setOffset(getIntParameter(request, "songOffset", 0));
SearchResult songs = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
for (MediaFile mediaFile : songs.getMediaFiles()) {
searchResult.getSong().add(createJaxbChild(player, mediaFile, username));
}
Response res = createResponse();
res.setSearchResult2(searchResult);
jaxbWriter.writeResponse(request, response, res);
}
Aggregations