Search in sources :

Example 1 with Search

use of org.codice.ddf.ui.searchui.query.model.Search in project ddf by codice.

the class SearchController method executeQuery.

/**
     * Execute all of the queries contained within the {@link SearchRequest}.
     *
     * @param request {@link SearchRequest} containing a query for 1 or more sources
     * @param session Cometd {@link ServerSession}
     */
public void executeQuery(final SearchRequest request, final ServerSession session, final Subject subject) {
    final Search search = new Search(request, actionRegistry);
    final Map<String, Result> results = Collections.synchronizedMap(new HashMap<String, Result>());
    final Future<FilteringSolrIndex> solrIndexFuture;
    if (shouldNormalizeRelevance(request)) {
        // Create in memory Solr instance asynchronously
        solrIndexFuture = executorService.submit(new FilteringSolrIndexCallable(request, filterAdapter));
    } else {
        solrIndexFuture = Futures.immediateFuture(null);
    }
    final Future cacheFuture;
    if (!cacheDisabled) {
        // Send any previously cached results
        cacheFuture = executorService.submit(new CacheQueryRunnable(this, request, subject, search, session, results, solrIndexFuture));
    } else {
        cacheFuture = Futures.immediateFuture(null);
    }
    long deadline = System.currentTimeMillis() + request.getQuery().getTimeoutMillis();
    Map<String, Future> futures = new HashMap<>(request.getSourceIds().size());
    for (final String sourceId : request.getSourceIds()) {
        // Send the latest results from each source
        futures.put(sourceId, executorService.submit(new SourceQueryRunnable(this, sourceId, request, subject, results, search, session, cacheFuture, solrIndexFuture)));
    }
    for (Map.Entry<String, Future> entry : futures.entrySet()) {
        executorService.submit(() -> {
            String sourceId = entry.getKey();
            Future future = entry.getValue();
            try {
                long timeRemaining = Math.max(0, deadline - System.currentTimeMillis());
                future.get(timeRemaining, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                LOGGER.info("Query interrupted for source {}", sourceId, e);
                failSource(request, session, search, sourceId, e);
            } catch (TimeoutException e) {
                LOGGER.info("Query timed out for source {}", sourceId, e);
                failSource(request, session, search, sourceId, e);
            } catch (ExecutionException e) {
                LOGGER.info("Query failed for source {}", sourceId, e.getCause());
                failSource(request, session, search, sourceId, e);
            }
        });
    }
}
Also used : HashMap(java.util.HashMap) FilteringSolrIndex(org.codice.ddf.ui.searchui.query.solr.FilteringSolrIndex) FilteringSolrIndexCallable(org.codice.ddf.ui.searchui.query.controller.search.FilteringSolrIndexCallable) CacheQueryRunnable(org.codice.ddf.ui.searchui.query.controller.search.CacheQueryRunnable) SourceQueryRunnable(org.codice.ddf.ui.searchui.query.controller.search.SourceQueryRunnable) Result(ddf.catalog.data.Result) Search(org.codice.ddf.ui.searchui.query.model.Search) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Result (ddf.catalog.data.Result)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 CacheQueryRunnable (org.codice.ddf.ui.searchui.query.controller.search.CacheQueryRunnable)1 FilteringSolrIndexCallable (org.codice.ddf.ui.searchui.query.controller.search.FilteringSolrIndexCallable)1 SourceQueryRunnable (org.codice.ddf.ui.searchui.query.controller.search.SourceQueryRunnable)1 Search (org.codice.ddf.ui.searchui.query.model.Search)1 FilteringSolrIndex (org.codice.ddf.ui.searchui.query.solr.FilteringSolrIndex)1