Search in sources :

Example 1 with FilteringSolrIndex

use of org.codice.ddf.ui.searchui.query.solr.FilteringSolrIndex 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)

Example 2 with FilteringSolrIndex

use of org.codice.ddf.ui.searchui.query.solr.FilteringSolrIndex in project ddf by codice.

the class SourceQueryRunnable method normalize.

private void normalize(Query query, List<Result> responseResults) {
    if (shouldNormalizeRelevance) {
        FilteringSolrIndex index = null;
        try {
            index = solrIndexFuture.get(FUTURE_TIMEOUT_SECONDS, TimeUnit.SECONDS);
            index.add(responseResults);
            List<Result> indexResults = index.query(new QueryRequestImpl(query)).getResults();
            normalizeRelevance(indexResults, results);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            LOGGER.debug("Failed to get index for relevance normalization", e);
        } catch (UnsupportedQueryException e) {
            LOGGER.debug("Failed to parse query for relevance normalization", e);
        } catch (IngestException e) {
            LOGGER.debug("Failed to ingest results for relevance normalization", e);
        }
    } else if (shouldNormalizeDistance) {
        normalizeDistances(query, results);
    }
}
Also used : FilteringSolrIndex(org.codice.ddf.ui.searchui.query.solr.FilteringSolrIndex) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) IngestException(ddf.catalog.source.IngestException) ExecutionException(java.util.concurrent.ExecutionException) Result(ddf.catalog.data.Result) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Result (ddf.catalog.data.Result)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 FilteringSolrIndex (org.codice.ddf.ui.searchui.query.solr.FilteringSolrIndex)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1 IngestException (ddf.catalog.source.IngestException)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)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