当前位置: 首页>>代码示例>>Java>>正文


Java SearchResult类代码示例

本文整理汇总了Java中net.sourceforge.subsonic.domain.SearchResult的典型用法代码示例。如果您正苦于以下问题:Java SearchResult类的具体用法?Java SearchResult怎么用?Java SearchResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SearchResult类属于net.sourceforge.subsonic.domain包,在下文中一共展示了SearchResult类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: forSearch

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
public MediaList forSearch(String query, int offset, int count, SearchService.IndexType indexType, String username, HttpServletRequest request) {

        SearchCriteria searchCriteria = new SearchCriteria();
        searchCriteria.setCount(count);
        searchCriteria.setOffset(offset);
        searchCriteria.setQuery(query);
        List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);

        SearchResult searchResult = searchService.search(searchCriteria, musicFolders, indexType);

        MediaList result = new MediaList();
        result.setTotal(searchResult.getTotalHits());
        result.setIndex(offset);
        result.setCount(searchResult.getMediaFiles().size());
        for (MediaFile mediaFile : searchResult.getMediaFiles()) {
            result.getMediaCollectionOrMediaMetadata().add(forMediaFile(mediaFile, username, request));
        }

        return result;
    }
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:21,代码来源:SonosHelper.java

示例2: search3

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
@SuppressWarnings("UnusedDeclaration")
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);
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:39,代码来源:RESTController.java

示例3: search

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
private List<MediaFile> search(String query, String username) throws IOException {
    SearchCriteria criteria = new SearchCriteria();
    criteria.setQuery(query);
    criteria.setOffset(0);
    criteria.setCount(50);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);

    SearchResult result = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
    return result.getMediaFiles();
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:11,代码来源:WapController.java

示例4: onSubmit

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object com, BindException errors)
        throws Exception {
    SearchCommand command = (SearchCommand) com;

    User user = securityService.getCurrentUser(request);
    UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
    command.setUser(user);
    command.setPartyModeEnabled(userSettings.isPartyModeEnabled());

    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
    String query = StringUtils.trimToNull(command.getQuery());

    if (query != null) {

        SearchCriteria criteria = new SearchCriteria();
        criteria.setCount(MATCH_COUNT);
        criteria.setQuery(query);

        SearchResult artists = searchService.search(criteria, musicFolders, SearchService.IndexType.ARTIST);
        command.setArtists(artists.getMediaFiles());

        SearchResult albums = searchService.search(criteria, musicFolders, SearchService.IndexType.ALBUM);
        command.setAlbums(albums.getMediaFiles());

        SearchResult songs = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
        command.setSongs(songs.getMediaFiles());

        command.setPlayer(playerService.getPlayer(request, response));
    }

    return new ModelAndView(getSuccessView(), errors.getModel());
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:34,代码来源:SearchController.java

示例5: search3

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
public void search3(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    XMLBuilder builder = createXMLBuilder(request, response, true);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    int userGroupId = securityService.getCurrentUserGroupId(request);
    
    builder.add("searchResult3", false);

    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 searchResult = searchService.search(criteria, SearchService.IndexType.ARTIST_ID3, userGroupId);
    for (Artist artist : searchResult.getArtists()) {
        builder.add("artist", createAttributesForArtist(artist, username), true);
    }

    criteria.setCount(getIntParameter(request, "albumCount", 20));
    criteria.setOffset(getIntParameter(request, "albumOffset", 0));
    searchResult = searchService.search(criteria, SearchService.IndexType.ALBUM_ID3, userGroupId);
    for (Album album : searchResult.getAlbums()) {
        builder.add("album", createAttributesForAlbum(album, username), true);
    }

    criteria.setCount(getIntParameter(request, "songCount", 20));
    criteria.setOffset(getIntParameter(request, "songOffset", 0));
    searchResult = searchService.search(criteria, SearchService.IndexType.SONG, userGroupId);
    for (MediaFile song : searchResult.getMediaFiles()) {
        builder.add("song", createAttributesForMediaFile(player, song, username), true);
    }

    builder.endAll();
    response.getWriter().print(builder);
}
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:37,代码来源:RESTController.java

示例6: search

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
private List<MediaFile> search(String query) throws IOException {
    SearchCriteria criteria = new SearchCriteria();
    criteria.setQuery(query);
    criteria.setOffset(0);
    criteria.setCount(50);

    SearchResult result = searchService.search(criteria, SearchService.IndexType.SONG, 0); //TODO: hardcoded
    return result.getMediaFiles();
}
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:10,代码来源:WapController.java

示例7: onSubmit

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object com, BindException errors)
        throws Exception {
    SearchCommand command = (SearchCommand) com;

    User user = securityService.getCurrentUser(request);
    UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
    
    int userGroupId = securityService.getCurrentUserGroupId(request); 
    
    command.setUser(user);
    command.setPartyModeEnabled(userSettings.isPartyModeEnabled());

    String any = StringUtils.trimToNull(command.getQuery());

    if (any != null) {

        SearchCriteria criteria = new SearchCriteria();
        criteria.setCount(MATCH_COUNT);
        criteria.setQuery(any);

        SearchResult artists = searchService.search(criteria, SearchService.IndexType.ARTIST, userGroupId);
        command.setArtists(artists.getMediaFiles());

        SearchResult albums = searchService.search(criteria, SearchService.IndexType.ALBUM, userGroupId);
        command.setAlbums(albums.getMediaFiles());

        SearchResult songs = searchService.search(criteria, SearchService.IndexType.SONG, userGroupId);
        command.setSongs(songs.getMediaFiles());

        command.setPlayer(playerService.getPlayer(request, response));
    }

    return new ModelAndView(getSuccessView(), errors.getModel());
}
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:36,代码来源:SearchController.java

示例8: search

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
@Deprecated
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.subsonic.restapi.SearchResult searchResult = new org.subsonic.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);
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:44,代码来源:RESTController.java

示例9: search

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
public SearchResult search(SearchCriteria criteria, List<MusicFolder> musicFolders, IndexType indexType) {
    SearchResult result = new SearchResult();
    int offset = criteria.getOffset();
    int count = criteria.getCount();
    result.setOffset(offset);

    IndexReader reader = null;
    try {
        reader = createIndexReader(indexType);
        Searcher searcher = new IndexSearcher(reader);
        Analyzer analyzer = new SubsonicAnalyzer();

        MultiFieldQueryParser queryParser = new MultiFieldQueryParser(LUCENE_VERSION, indexType.getFields(), analyzer, indexType.getBoosts());

        BooleanQuery query = new BooleanQuery();
        query.add(queryParser.parse(analyzeQuery(criteria.getQuery())), BooleanClause.Occur.MUST);

        List<SpanTermQuery> musicFolderQueries = new ArrayList<SpanTermQuery>();
        for (MusicFolder musicFolder : musicFolders) {
            if (indexType == ALBUM_ID3 || indexType == ARTIST_ID3) {
                musicFolderQueries.add(new SpanTermQuery(new Term(FIELD_FOLDER_ID, NumericUtils.intToPrefixCoded(musicFolder.getId()))));
            } else {
                musicFolderQueries.add(new SpanTermQuery(new Term(FIELD_FOLDER, musicFolder.getPath().getPath())));
            }
        }
        query.add(new SpanOrQuery(musicFolderQueries.toArray(new SpanQuery[musicFolderQueries.size()])), BooleanClause.Occur.MUST);

        TopDocs topDocs = searcher.search(query, null, offset + count);
        result.setTotalHits(topDocs.totalHits);

        int start = Math.min(offset, topDocs.totalHits);
        int end = Math.min(start + count, topDocs.totalHits);
        for (int i = start; i < end; i++) {
            Document doc = searcher.doc(topDocs.scoreDocs[i].doc);
            switch (indexType) {
                case SONG:
                case ARTIST:
                case ALBUM:
                    MediaFile mediaFile = mediaFileService.getMediaFile(Integer.valueOf(doc.get(FIELD_ID)));
                    addIfNotNull(mediaFile, result.getMediaFiles());
                    break;
                case ARTIST_ID3:
                    Artist artist = artistDao.getArtist(Integer.valueOf(doc.get(FIELD_ID)));
                    addIfNotNull(artist, result.getArtists());
                    break;
                case ALBUM_ID3:
                    Album album = albumDao.getAlbum(Integer.valueOf(doc.get(FIELD_ID)));
                    addIfNotNull(album, result.getAlbums());
                    break;
                default:
                    break;
            }
        }

    } catch (Throwable x) {
        LOG.error("Failed to execute Lucene search.", x);
    } finally {
        FileUtil.closeQuietly(reader);
    }
    return result;
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:62,代码来源:SearchService.java

示例10: search

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
@Deprecated
public void search(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    XMLBuilder builder = createXMLBuilder(request, response, true);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    int userGroupId = securityService.getCurrentUserGroupId(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));

    SearchResult result = searchService.search(criteria, SearchService.IndexType.SONG, userGroupId);
    builder.add("searchResult", false,
            new Attribute("offset", result.getOffset()),
            new Attribute("totalHits", result.getTotalHits()));

    for (MediaFile mediaFile : result.getMediaFiles()) {
        AttributeSet attributes = createAttributesForMediaFile(player, mediaFile, username);
        builder.add("match", attributes, true);
    }
    builder.endAll();
    response.getWriter().print(builder);
}
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:45,代码来源:RESTController.java

示例11: search

import net.sourceforge.subsonic.domain.SearchResult; //导入依赖的package包/类
public SearchResult search(SearchCriteria criteria, IndexType indexType, int user_group_id) {
     SearchResult result = new SearchResult();
     int offset = criteria.getOffset();
     int count = criteria.getCount();
     result.setOffset(offset);

     IndexReader reader = null;
     try {
         reader = createIndexReader(indexType);
         Searcher searcher = new IndexSearcher(reader);
         Analyzer analyzer = new SubsonicAnalyzer();

         MultiFieldQueryParser queryParser = new MultiFieldQueryParser(LUCENE_VERSION, indexType.getFields(), analyzer, indexType.getBoosts());
queryParser.setAllowLeadingWildcard(true);
         Query query = queryParser.parse(criteria.getQuery());

         TopDocs topDocs = searcher.search(query, null, offset + count);
         result.setTotalHits(topDocs.totalHits);

         int start = Math.min(offset, topDocs.totalHits);
         int end = Math.min(start + count, topDocs.totalHits);
         for (int i = start; i < end; i++) {
             Document doc = searcher.doc(topDocs.scoreDocs[i].doc);
             switch (indexType) {
                 case SONG:
                 case ARTIST:
                 case ALBUM:
                     MediaFile mediaFile = mediaFileService.getMediaFile(Integer.valueOf(doc.get(FIELD_ID)), user_group_id);
                     addIfNotNull(mediaFile, result.getMediaFiles());
                     break;
                 case ARTIST_ID3:
                     Artist artist = artistDao.getArtist(Integer.valueOf(doc.get(FIELD_ID)));
                     addIfNotNull(artist, result.getArtists());
                     break;
                 case ALBUM_ID3:
                     Album album = albumDao.getAlbum(Integer.valueOf(doc.get(FIELD_ID)));
                     addIfNotNull(album, result.getAlbums());
                     break;
                 default:
                     break;
             }
         }

     } catch (Throwable x) {
         LOG.error("Failed to execute Lucene search.", x);
     } finally {
         FileUtil.closeQuietly(reader);
     }
     return result;
 }
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:51,代码来源:SearchService.java


注:本文中的net.sourceforge.subsonic.domain.SearchResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。