Search in sources :

Example 1 with AcceptorResult

use of org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult in project nzbhydra2 by theotherp.

the class Indexer method searchInternal.

protected IndexerSearchResult searchInternal(SearchRequest searchRequest, int offset, Integer limit) throws IndexerSearchAbortedException, IndexerAccessException {
    UriComponentsBuilder builder = buildSearchUrl(searchRequest, offset, limit);
    URI url = builder.build().toUri();
    T response;
    Stopwatch stopwatch = Stopwatch.createStarted();
    info("Calling {}", url.toString());
    response = getAndStoreResultToDatabase(url, IndexerApiAccessType.SEARCH);
    long responseTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
    stopwatch.reset();
    stopwatch.start();
    IndexerSearchResult indexerSearchResult = new IndexerSearchResult(this, true);
    List<SearchResultItem> searchResultItems = getSearchResultItems(response);
    info("Successfully executed search call in {}ms with {} results", responseTime, searchResultItems.size());
    AcceptorResult acceptorResult = resultAcceptor.acceptResults(searchResultItems, searchRequest, config);
    searchResultItems = acceptorResult.getAcceptedResults();
    indexerSearchResult.setReasonsForRejection(acceptorResult.getReasonsForRejection());
    searchResultItems = persistSearchResults(searchResultItems);
    indexerSearchResult.setSearchResultItems(searchResultItems);
    indexerSearchResult.setResponseTime(responseTime);
    completeIndexerSearchResult(response, indexerSearchResult, acceptorResult, searchRequest);
    int endIndex = Math.min(indexerSearchResult.getOffset() + indexerSearchResult.getLimit(), indexerSearchResult.getOffset() + searchResultItems.size());
    debug("Returning results {}-{} of {} available ({} already rejected)", indexerSearchResult.getOffset(), endIndex, indexerSearchResult.getTotalResults(), acceptorResult.getNumberOfRejectedResults());
    return indexerSearchResult;
}
Also used : AcceptorResult(org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Stopwatch(com.google.common.base.Stopwatch) URI(java.net.URI)

Example 2 with AcceptorResult

use of org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult in project nzbhydra2 by theotherp.

the class NewznabTest method shouldAccountForRejectedResults.

@Test
public void shouldAccountForRejectedResults() throws Exception {
    List<NewznabXmlItem> items = Arrays.asList(RssItemBuilder.builder("title1").build(), RssItemBuilder.builder("title2").build(), RssItemBuilder.builder("title3").build(), RssItemBuilder.builder("title4").build(), RssItemBuilder.builder("title5").build());
    NewznabXmlRoot root = RssBuilder.builder().items(items).newznabResponse(100, 105).build();
    when(indexerWebAccessMock.get(any(), eq(testee.config), any())).thenReturn(root);
    // Two items will be rejected
    when(resultAcceptorMock.acceptResults(any(), any(), any())).thenAnswer(new Answer<AcceptorResult>() {

        @Override
        public AcceptorResult answer(InvocationOnMock invocation) throws Throwable {
            List<SearchResultItem> argument = invocation.getArgument(0);
            HashMultiset<String> reasonsForRejection = HashMultiset.create();
            reasonsForRejection.add("some reason", 2);
            return new AcceptorResult(argument.subList(0, 3), reasonsForRejection);
        }
    });
    IndexerSearchResult indexerSearchResult = testee.searchInternal(new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100), 0, 100);
    assertThat(indexerSearchResult.getSearchResultItems().size(), is(3));
    assertThat(indexerSearchResult.getTotalResults(), is(105));
    assertThat(indexerSearchResult.isHasMoreResults(), is(false));
    assertThat(indexerSearchResult.isTotalResultsKnown(), is(true));
}
Also used : AcceptorResult(org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult) SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HashMultiset(com.google.common.collect.HashMultiset) Test(org.junit.Test)

Example 3 with AcceptorResult

use of org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult in project nzbhydra2 by theotherp.

the class NewznabTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    testee = spy(testee);
    when(infoProviderMock.canConvert(IdType.IMDB, IdType.TMDB)).thenReturn(true);
    MediaInfo info = new MediaInfo();
    info.setImdbId("imdbId");
    info.setTmdbId("tmdbId");
    info.setTvmazeId("tvmazeId");
    info.setTvrageId("tvrageId");
    info.setTvdbId("tvdbId");
    when(infoProviderMock.convert("imdbId", IdType.IMDB)).thenReturn(info);
    when(infoProviderMock.convert(anyMap())).thenReturn(info);
    when(infoProviderMock.convert("tvmazeId", IdType.TVMAZE)).thenReturn(info);
    // when(indexerEntityMock.getStatus()).thenReturn(indexerStatusEntityMock);
    testee.config = new IndexerConfig();
    testee.config.setSupportedSearchIds(Lists.newArrayList(IdType.TMDB, IdType.TVRAGE));
    testee.config.setHost("http://127.0.0.1:1234");
    baseConfig = new BaseConfig();
    when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
    baseConfig.getSearching().setRemoveTrailing(Collections.emptyList());
    baseConfig.getSearching().setGenerateQueries(SearchSourceRestriction.NONE);
    when(resultAcceptorMock.acceptResults(any(), any(), any())).thenAnswer(new Answer<AcceptorResult>() {

        @Override
        public AcceptorResult answer(InvocationOnMock invocation) throws Throwable {
            return new AcceptorResult(invocation.getArgument(0), HashMultiset.create());
        }
    });
    animeCategory.setSubtype(Subtype.ANIME);
    when(categoryProviderMock.fromSubtype(Subtype.ANIME)).thenReturn(Optional.of(animeCategory));
    when(categoryProviderMock.fromSearchNewznabCategories(any(), any())).thenAnswer(x -> x.getArgument(1));
    when(categoryProviderMock.getNotAvailable()).thenReturn(naCategory);
}
Also used : AcceptorResult(org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Example 4 with AcceptorResult

use of org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult in project nzbhydra2 by theotherp.

the class IndexerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(indexerMock.getIndexerEntity()).thenReturn(indexerEntityMock);
    when(indexerMock.getConfig()).thenReturn(indexerConfig);
    when(indexerEntityMock.getName()).thenReturn("indexerName");
    when(indexerMock.getName()).thenReturn("indexerName");
    testee.indexer = indexerEntityMock;
    testee.config = indexerConfig;
    indexerConfig.setTimeout(1);
    baseConfig = new BaseConfig();
    when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
    baseConfig.getSearching().setIdFallbackToQueryGeneration(SearchSourceRestriction.BOTH);
    when(resultAcceptor.acceptResults(anyList(), any(), any())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return new AcceptorResult(invocation.getArgument(0), HashMultiset.create());
        }
    });
    when(infoProviderMock.convert(anyString(), any())).thenReturn(new MediaInfo(new TvInfo("tvdbid", "tvrageid", "tvmazeid", "title", 2017, "")));
    testee = spy(testee);
}
Also used : AcceptorResult(org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TvInfo(org.nzbhydra.mediainfo.TvInfo) BaseConfig(org.nzbhydra.config.BaseConfig) Before(org.junit.Before)

Aggregations

AcceptorResult (org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Before (org.junit.Before)2 MediaInfo (org.nzbhydra.mediainfo.MediaInfo)2 Stopwatch (com.google.common.base.Stopwatch)1 HashMultiset (com.google.common.collect.HashMultiset)1 URI (java.net.URI)1 Test (org.junit.Test)1 BaseConfig (org.nzbhydra.config.BaseConfig)1 TvInfo (org.nzbhydra.mediainfo.TvInfo)1 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1