use of org.nzbhydra.searching.IndexerForSearchSelector.IndexerForSearchSelection 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;
}
Aggregations