Search in sources :

Example 1 with IndexerForSearchSelection

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;
}
Also used : Iterables(com.google.common.collect.Iterables) java.util(java.util) Getter(lombok.Getter) IndexerSearchEntity(org.nzbhydra.indexers.IndexerSearchEntity) Stopwatch(com.google.common.base.Stopwatch) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SearchSource(org.nzbhydra.searching.searchrequests.SearchRequest.SearchSource) Indexer(org.nzbhydra.indexers.Indexer) ConfigProvider(org.nzbhydra.config.ConfigProvider) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) IndexerSearchRepository(org.nzbhydra.indexers.IndexerSearchRepository) SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) Logger(org.slf4j.Logger) java.util.concurrent(java.util.concurrent) ExpiringMap(net.jodah.expiringmap.ExpiringMap) EventListener(org.springframework.context.event.EventListener) IndexerForSearchSelection(org.nzbhydra.searching.IndexerForSearchSelector.IndexerForSearchSelection) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ShutdownEvent(org.nzbhydra.ShutdownEvent) Component(org.springframework.stereotype.Component) Entry(java.util.Map.Entry) ExpirationPolicy(net.jodah.expiringmap.ExpirationPolicy) MdcThreadPoolExecutor(org.nzbhydra.logging.MdcThreadPoolExecutor) LoggingMarkers(org.nzbhydra.logging.LoggingMarkers) IndexerSearchEntity(org.nzbhydra.indexers.IndexerSearchEntity) IndexerForSearchSelection(org.nzbhydra.searching.IndexerForSearchSelector.IndexerForSearchSelection)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 Instant (java.time.Instant)1 java.util (java.util)1 Entry (java.util.Map.Entry)1 java.util.concurrent (java.util.concurrent)1 Collectors (java.util.stream.Collectors)1 Getter (lombok.Getter)1 ExpirationPolicy (net.jodah.expiringmap.ExpirationPolicy)1 ExpiringMap (net.jodah.expiringmap.ExpiringMap)1 ShutdownEvent (org.nzbhydra.ShutdownEvent)1 ConfigProvider (org.nzbhydra.config.ConfigProvider)1 Indexer (org.nzbhydra.indexers.Indexer)1 IndexerSearchEntity (org.nzbhydra.indexers.IndexerSearchEntity)1 IndexerSearchRepository (org.nzbhydra.indexers.IndexerSearchRepository)1 LoggingMarkers (org.nzbhydra.logging.LoggingMarkers)1 MdcThreadPoolExecutor (org.nzbhydra.logging.MdcThreadPoolExecutor)1 IndexerForSearchSelection (org.nzbhydra.searching.IndexerForSearchSelector.IndexerForSearchSelection)1 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)1