use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class SearcherUnitTest method shouldWorkWithRejectedItems.
@Test
public void shouldWorkWithRejectedItems() throws Exception {
IndexerSearchResult result1 = mockIndexerSearchResult(0, 9, true, 20, indexer1);
Multiset<String> reasons = HashMultiset.create();
reasons.add("foobar");
result1.setReasonsForRejection(reasons);
result1.setLimit(10);
when(indexer1.search(any(), anyInt(), anyInt())).thenReturn(result1, mockIndexerSearchResult(11, 10, false, 20, indexer1));
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 10);
searchRequest.setTitle("some title so it will be found in the search request cache");
SearchResult result = searcher.search(searchRequest);
List<SearchResultItem> foundResults = result.getSearchResultItems();
assertThat(foundResults.size(), is(10));
searchRequest.setOffset(10);
searchRequest.setLimit(100);
result = searcher.search(searchRequest);
foundResults = result.getSearchResultItems();
assertThat(foundResults.size(), is(9));
verify(indexer1).search(any(), eq(0), any());
verify(indexer1, times(2)).search(any(), anyInt(), any());
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class SearcherUnitTest method shouldFollowOffsetAndLimit.
@Test
public void shouldFollowOffsetAndLimit() throws Exception {
when(indexer1.search(any(), anyInt(), anyInt())).thenReturn(mockIndexerSearchResult(0, 2, true, 200, indexer1));
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 1);
searchRequest.setTitle("some title so it will be found in the search request cache");
SearchResult result = searcher.search(searchRequest);
List<SearchResultItem> foundResults = result.getSearchResultItems();
assertThat(foundResults.size(), is(1));
assertThat(foundResults.get(0).getTitle(), is("item0"));
searchRequest.setOffset(1);
result = searcher.search(searchRequest);
foundResults = result.getSearchResultItems();
assertThat(foundResults.size(), is(1));
assertThat(foundResults.get(0).getTitle(), is("item1"));
verify(indexer1).search(any(), eq(0), any());
verify(indexer1, times(1)).search(any(), anyInt(), any());
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class AnizbTest method shouldAddRequiredWords.
@Test
public void shouldAddRequiredWords() throws IndexerSearchAbortedException {
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
searchRequest.getInternalData().setRequiredWords(Arrays.asList("a", "b"));
searchRequest.setQuery("query");
UriComponentsBuilder builder = testee.buildSearchUrl(searchRequest, 0, 100);
assertThat(builder.toUriString(), is("https://anizb.org/api/?q=query%20a%20b"));
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class BinsearchTest method shouldAbortIfSearchNotPossible.
@Test(expected = IndexerSearchAbortedException.class)
public void shouldAbortIfSearchNotPossible() throws IndexerSearchAbortedException {
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
testee.buildSearchUrl(searchRequest, 0, 100);
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class BinsearchTest method shouldRecognizeIfSingleResultPage.
@Test
public void shouldRecognizeIfSingleResultPage() throws Exception {
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
String html = Resources.toString(Resources.getResource(BinsearchTest.class, "/org/nzbhydra/mapping/binsearch_singlepage.html"), Charsets.UTF_8);
IndexerSearchResult indexerSearchResult = new IndexerSearchResult(testee, "");
List<SearchResultItem> items = new ArrayList<>();
for (int i = 0; i < 24; i++) {
items.add(new SearchResultItem());
}
indexerSearchResult.setSearchResultItems(items);
testee.completeIndexerSearchResult(html, indexerSearchResult, null, searchRequest);
assertThat(indexerSearchResult.getOffset(), is(0));
assertThat(indexerSearchResult.getLimit(), is(100));
assertThat(indexerSearchResult.getTotalResults(), is(24));
assertThat(indexerSearchResult.isTotalResultsKnown(), is(true));
assertThat(indexerSearchResult.isHasMoreResults(), is(false));
}
Aggregations