use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class SearchWeb method createSearchRequest.
private SearchRequest createSearchRequest(@RequestBody SearchRequestParameters parameters) {
Category category = categoryProvider.getByInternalName(parameters.getCategory());
SearchType searchType = category.getSearchType() == null ? SearchType.SEARCH : category.getSearchType();
SearchRequest searchRequest = searchRequestFactory.getSearchRequest(searchType, SearchSource.INTERNAL, category, parameters.getSearchRequestId(), parameters.getOffset(), parameters.getLimit());
searchRequest.setLoadAll(parameters.isLoadAll());
searchRequest.setIndexers(parameters.getIndexers());
searchRequest.setQuery(parameters.getQuery());
searchRequest.setMinage(parameters.getMinage());
searchRequest.setMaxage(parameters.getMaxage());
searchRequest.setMinsize(parameters.getMinsize());
searchRequest.setMaxsize(parameters.getMaxsize());
if (!Strings.isNullOrEmpty(parameters.getTitle())) {
searchRequest.setTitle(parameters.getTitle());
}
if (!Strings.isNullOrEmpty(parameters.getImdbId())) {
searchRequest.getIdentifiers().put(IdType.IMDB, parameters.getImdbId());
}
if (!Strings.isNullOrEmpty(parameters.getTmdbId())) {
searchRequest.getIdentifiers().put(IdType.TMDB, parameters.getTmdbId());
}
if (!Strings.isNullOrEmpty(parameters.getTvrageId())) {
searchRequest.getIdentifiers().put(IdType.TVRAGE, parameters.getTvrageId());
}
if (!Strings.isNullOrEmpty(parameters.getTvdbId())) {
searchRequest.getIdentifiers().put(IdType.TVDB, parameters.getTvdbId());
}
if (!Strings.isNullOrEmpty(parameters.getTvmazeId())) {
searchRequest.getIdentifiers().put(IdType.TVMAZE, parameters.getTvmazeId());
}
if (parameters.getSeason() != null) {
searchRequest.setSeason(parameters.getSeason());
}
if (!Strings.isNullOrEmpty(parameters.getEpisode())) {
searchRequest.setEpisode(parameters.getEpisode());
}
if (!searchRequest.getIdentifiers().isEmpty() && searchRequest.getQuery().isPresent()) {
// Add additional restrictions to required words
logger.debug("Adding additional search terms '{}' to required words", searchRequest.getQuery().get());
searchRequest.getInternalData().getRequiredWords().addAll(Splitter.on(" ").splitToList(searchRequest.getQuery().get()));
// Remove query, would be ignored by most indexers anyway
searchRequest.setQuery(null);
}
searchRequest = searchRequestFactory.extendWithSavedIdentifiers(searchRequest);
// Initialize messages for this search request
searchStates.put(searchRequest.getSearchRequestId(), new SearchState());
return searchRequest;
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class Searcher method getSearchCacheEntry.
protected SearchCacheEntry getSearchCacheEntry(SearchRequest searchRequest) {
SearchCacheEntry searchCacheEntry;
if (searchRequest.getOffset().orElse(0) == 0 || !searchRequestCache.containsKey(searchRequest.hashCode())) {
// New search
SearchEntity searchEntity = new SearchEntity();
searchEntity.setSource(searchRequest.getSource());
searchEntity.setCategoryName(searchRequest.getCategory().getName());
searchEntity.setQuery(searchRequest.getQuery().orElse(null));
searchEntity.setIdentifiers(searchRequest.getIdentifiers().entrySet().stream().filter(x -> x.getValue() != null).map(x -> new IdentifierKeyValuePair(x.getKey().name(), x.getValue())).collect(Collectors.toSet()));
searchEntity.setSeason(searchRequest.getSeason().orElse(null));
searchEntity.setEpisode(searchRequest.getEpisode().orElse(null));
searchEntity.setSearchType(searchRequest.getSearchType());
searchEntity.setTitle(searchRequest.getTitle().orElse(null));
searchEntity.setAuthor(searchRequest.getAuthor().orElse(null));
// Extend search request
searchRequest.extractForbiddenWords();
searchRepository.save(searchEntity);
IndexerForSearchSelection pickingResult = indexerPicker.pickIndexers(searchRequest);
searchCacheEntry = new SearchCacheEntry(searchRequest, pickingResult, searchEntity);
} else {
searchCacheEntry = searchRequestCache.get(searchRequest.hashCode());
searchCacheEntry.setLastAccessed(Instant.now());
// Update to latest to keep offset and limit updated
searchCacheEntry.setSearchRequest(searchRequest);
}
return searchCacheEntry;
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class ExternalApi method buildBaseSearchRequest.
private SearchRequest buildBaseSearchRequest(NewznabParameters params) {
SearchType searchType = SearchType.valueOf(params.getT().name());
SearchRequest searchRequest = searchRequestFactory.getSearchRequest(searchType, SearchSource.API, categoryProvider.fromSearchNewznabCategories(params.getCat(), CategoriesConfig.allCategory), random.nextInt(1000000), params.getOffset(), params.getLimit());
logger.info("Executing new search");
searchRequest.setQuery(params.getQ());
searchRequest.setLimit(params.getLimit());
searchRequest.setOffset(params.getOffset());
// Not part of spec
searchRequest.setMinage(params.getMinage());
searchRequest.setMaxage(params.getMaxage());
// Not part of spec
searchRequest.setMinsize(params.getMinsize());
// Not part of spec
searchRequest.setMaxsize(params.getMaxsize());
searchRequest.setAuthor(params.getAuthor());
searchRequest.setTitle(params.getTitle());
searchRequest.setSeason(params.getSeason());
searchRequest.setEpisode(params.getEp());
if (params.getCat() != null) {
searchRequest.getInternalData().setNewznabCategories(params.getCat());
}
if (!Strings.isNullOrEmpty(params.getTvdbid())) {
searchRequest.getIdentifiers().put(IdType.TVDB, params.getTvdbid());
}
if (!Strings.isNullOrEmpty(params.getTvmazeid())) {
searchRequest.getIdentifiers().put(IdType.TVMAZE, params.getTvmazeid());
}
if (!Strings.isNullOrEmpty(params.getRid())) {
searchRequest.getIdentifiers().put(IdType.TVRAGE, params.getRid());
}
if (!Strings.isNullOrEmpty(params.getImdbid())) {
searchRequest.getIdentifiers().put(IdType.IMDB, params.getImdbid());
}
if (!Strings.isNullOrEmpty(params.getTmdbid())) {
searchRequest.getIdentifiers().put(IdType.TMDB, params.getTmdbid());
}
searchRequest = searchRequestFactory.extendWithSavedIdentifiers(searchRequest);
return searchRequest;
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class ExternalApi method search.
protected NewznabResponse search(NewznabParameters params) {
Stopwatch stopwatch = Stopwatch.createStarted();
SearchRequest searchRequest = buildBaseSearchRequest(params);
if (isTorznabCall()) {
searchRequest.setDownloadType(org.nzbhydra.searching.DownloadType.TORRENT);
} else {
searchRequest.setDownloadType(org.nzbhydra.searching.DownloadType.NZB);
}
SearchResult searchResult = searcher.search(searchRequest);
NewznabResponse transformedResults = transformResults(searchResult, params, searchRequest);
logger.info("Search took {}ms. Returning {} results", stopwatch.elapsed(TimeUnit.MILLISECONDS), searchResult.getSearchResultItems().size());
return transformedResults;
}
use of org.nzbhydra.searching.searchrequests.SearchRequest in project nzbhydra2 by theotherp.
the class NzbsOrgTest method shouldLimitQueryLengthWhenAddingForbiddenWords.
@Test
public void shouldLimitQueryLengthWhenAddingForbiddenWords() throws Exception {
SearchRequest request = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
request.getInternalData().setForbiddenWords(Arrays.asList("characters50sssssssssssssssssssssssssssssssssssss1", "characters50sssssssssssssssssssssssssssssssssssss2", "characters50sssssssssssssssssssssssssssssssssssss3", "characters50sssssssssssssssssssssssssssssssssssss4", "characters40ssssssssssssssssssssssssssss", "aaaaa", "bbbbb"));
String query = testee.addForbiddenWords(request, "");
assertThat(query.length()).isLessThan(255);
}
Aggregations