Package org.elasticsearch.search.query

Examples of org.elasticsearch.search.query.QuerySearchResult


    public InternalSearchResponse merge(ShardDoc[] sortedDocs, Map<SearchShardTarget, ? extends QuerySearchResultProvider> queryResults, Map<SearchShardTarget, ? extends FetchSearchResultProvider> fetchResults) {

        boolean sorted = false;
        int sortScoreIndex = -1;
        QuerySearchResult querySearchResult;
        try {
            querySearchResult = Iterables.get(queryResults.values(), 0).queryResult();
        } catch (IndexOutOfBoundsException e) {
            // no results, return an empty response
            return InternalSearchResponse.EMPTY;
        }

        if (querySearchResult.topDocs() instanceof TopFieldDocs) {
            sorted = true;
            TopFieldDocs fieldDocs = (TopFieldDocs) querySearchResult.queryResult().topDocs();
            for (int i = 0; i < fieldDocs.fields.length; i++) {
                if (fieldDocs.fields[i].getType() == SortField.SCORE) {
                    sortScoreIndex = i;
                }
            }
        }

        // merge facets
        InternalFacets facets = null;
        if (!queryResults.isEmpty()) {
            // we rely on the fact that the order of facets is the same on all query results
            if (querySearchResult.facets() != null && querySearchResult.facets().facets() != null && !querySearchResult.facets().facets().isEmpty()) {
                List<Facet> aggregatedFacets = Lists.newArrayList();
                List<Facet> namedFacets = Lists.newArrayList();
                for (Facet facet : querySearchResult.facets()) {
                    // aggregate each facet name into a single list, and aggregate it
                    namedFacets.clear();
                    for (QuerySearchResultProvider queryResultProvider : queryResults.values()) {
                        for (Facet facet1 : queryResultProvider.queryResult().facets()) {
                            if (facet.name().equals(facet1.name())) {
View Full Code Here


    }

    public void sendExecuteQuery(DiscoveryNode node, final InternalSearchRequest request, final SearchServiceListener<QuerySearchResult> listener) {
        if (clusterService.state().nodes().localNodeId().equals(node.id())) {
            try {
                QuerySearchResult result = searchService.executeQueryPhase(request);
                listener.onResult(result);
            } catch (Exception e) {
                listener.onFailure(e);
            }
        } else {
            transportService.sendRequest(node, SearchQueryTransportHandler.ACTION, request, new BaseTransportResponseHandler<QuerySearchResult>() {

                @Override public QuerySearchResult newInstance() {
                    return new QuerySearchResult();
                }

                @Override public void handleResponse(QuerySearchResult response) {
                    listener.onResult(response);
                }
View Full Code Here

    }

    public void sendExecuteQuery(DiscoveryNode node, final QuerySearchRequest request, final SearchServiceListener<QuerySearchResult> listener) {
        if (clusterService.state().nodes().localNodeId().equals(node.id())) {
            try {
                QuerySearchResult result = searchService.executeQueryPhase(request);
                listener.onResult(result);
            } catch (Exception e) {
                listener.onFailure(e);
            }
        } else {
            transportService.sendRequest(node, SearchQueryByIdTransportHandler.ACTION, request, new BaseTransportResponseHandler<QuerySearchResult>() {

                @Override public QuerySearchResult newInstance() {
                    return new QuerySearchResult();
                }

                @Override public void handleResponse(QuerySearchResult response) {
                    listener.onResult(response);
                }
View Full Code Here

    }

    public void sendExecuteScan(DiscoveryNode node, final InternalSearchRequest request, final SearchServiceListener<QuerySearchResult> listener) {
        if (clusterService.state().nodes().localNodeId().equals(node.id())) {
            try {
                QuerySearchResult result = searchService.executeScan(request);
                listener.onResult(result);
            } catch (Exception e) {
                listener.onFailure(e);
            }
        } else {
            transportService.sendRequest(node, SearchScanTransportHandler.ACTION, request, new BaseTransportResponseHandler<QuerySearchResult>() {

                @Override public QuerySearchResult newInstance() {
                    return new QuerySearchResult();
                }

                @Override public void handleResponse(QuerySearchResult response) {
                    listener.onResult(response);
                }
View Full Code Here

        @Override public InternalSearchRequest newInstance() {
            return new InternalSearchRequest();
        }

        @Override public void messageReceived(InternalSearchRequest request, TransportChannel channel) throws Exception {
            QuerySearchResult result = searchService.executeQueryPhase(request);
            channel.sendResponse(result);
        }
View Full Code Here

        @Override public QuerySearchRequest newInstance() {
            return new QuerySearchRequest();
        }

        @Override public void messageReceived(QuerySearchRequest request, TransportChannel channel) throws Exception {
            QuerySearchResult result = searchService.executeQueryPhase(request);
            channel.sendResponse(result);
        }
View Full Code Here

        this.timeout = timeout;
        this.types = types;
        this.engineSearcher = engineSearcher;
        this.scriptService = scriptService;
        this.dfsResult = new DfsSearchResult(id, shardTarget);
        this.queryResult = new QuerySearchResult(id, shardTarget);
        this.fetchResult = new FetchSearchResult(id, shardTarget);
        this.indexService = indexService;

        this.searcher = new ContextIndexSearcher(this, engineSearcher);
    }
View Full Code Here

        @Override public InternalSearchRequest newInstance() {
            return new InternalSearchRequest();
        }

        @Override public void messageReceived(InternalSearchRequest request, TransportChannel channel) throws Exception {
            QuerySearchResult result = searchService.executeScan(request);
            channel.sendResponse(result);
        }
View Full Code Here

                docIdsToLoad.set(0, IntArrayList.from(1));
                return null;
            }
        }).when(searchPhaseController).fillDocIdsToLoad(any(AtomicArray.class), any(ScoreDoc[].class));

        QuerySearchResult queryResult = mock(QuerySearchResult.class, Answers.RETURNS_DEEP_STUBS.get());

        SearchShardTarget target = mock(SearchShardTarget.class);
        when(target.nodeId()).thenReturn("node_1");
        when(queryResult.shardTarget()).thenReturn(target);

        queryThenFetchTask.start();
        verify(transportQueryShardAction).execute(anyString(), any(QueryShardRequest.class), responseListener.capture());
        responseListener.getValue().onResponse(queryResult);
View Full Code Here

        new AsyncAction(node, request, listener).start();
    }

    private void shardOperation(QueryShardRequest request, ActionListener<QuerySearchResult> listener) {
        try {
            QuerySearchResult querySearchResult = searchService.executeQueryPhase(request);
            listener.onResponse(querySearchResult);
        } catch (Exception e) {
            listener.onFailure(e);
        }
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.query.QuerySearchResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.