Package org.elasticsearch.search.suggest

Examples of org.elasticsearch.search.suggest.Suggest


    @Override
    protected XContentBuilder toXContent(SuggestRequest request, SuggestResponse response, XContentBuilder builder) throws IOException {
        builder.startObject();
        buildBroadcastShardsHeader(builder, response);
        Suggest suggest = response.getSuggest();
        if (suggest != null) {
            suggest.toXContent(builder, ToXContent.EMPTY_PARAMS);
        }
        builder.endObject();
        return builder;
    }
View Full Code Here


        client.suggest(suggestRequest, new RestBuilderListener<SuggestResponse>(channel) {
            @Override
            public RestResponse buildResponse(SuggestResponse response, XContentBuilder builder) throws Exception {
                builder.startObject();
                buildBroadcastShardsHeader(builder, response);
                Suggest suggest = response.getSuggest();
                if (suggest != null) {
                    suggest.toXContent(builder, request);
                }
                builder.endObject();
                return new BytesRestResponse(OK, builder);
            }
        });
View Full Code Here

class ShardSuggestResponse extends BroadcastShardOperationResponse {

    private final Suggest suggest;

    ShardSuggestResponse() {
        this.suggest = new Suggest();
    }
View Full Code Here

        super(NAME);
    }

    @Override
    public SuggestResponse newResponse() {
        return new SuggestResponse(new Suggest());
    }
View Full Code Here

                if (shardFailures == null) {
                    shardFailures = newArrayList();
                }
                shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
            } else {
                Suggest suggest = ((ShardSuggestResponse) shardResponse).getSuggest();
                Suggest.group(groupedSuggestions, suggest);
                successfulShards++;
            }
        }

        return new SuggestResponse(new Suggest(Suggest.reduce(groupedSuggestions)), shardsResponses.length(), successfulShards, failedShards, shardFailures);
    }
View Full Code Here

                parser = XContentFactory.xContent(suggest).createParser(suggest);
                if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
                    throw new ElasticsearchIllegalArgumentException("suggest content missing");
                }
                final SuggestionSearchContext context = suggestPhase.parseElement().parseInternal(parser, indexService.mapperService(), request.shardId().getIndex(), request.shardId().id());
                final Suggest result = suggestPhase.execute(context, searcher.reader());
                return new ShardSuggestResponse(request.shardId(), result);
            }
            return new ShardSuggestResponse(request.shardId(), new Suggest());
        } catch (Throwable ex) {
            throw new ElasticsearchException("failed to execute suggest", ex);
        } finally {
            searcher.close();
            if (parser != null) {
View Full Code Here

                }
            }
        }

        // merge suggest results
        Suggest suggest = null;
        if (!queryResults.isEmpty()) {
            final Map<String, List<Suggest.Suggestion>> groupedSuggestions = new HashMap<>();
            boolean hasSuggestions = false;
            for (AtomicArray.Entry<? extends QuerySearchResultProvider> entry : queryResults) {
                Suggest shardResult = entry.value.queryResult().queryResult().suggest();

                if (shardResult == null) {
                    continue;
                }
                hasSuggestions = true;
                Suggest.group(groupedSuggestions, shardResult);
            }

            suggest = hasSuggestions ? new Suggest(Suggest.Fields.SUGGEST, Suggest.reduce(groupedSuggestions)) : null;
        }

        // merge addAggregation
        InternalAggregations aggregations = null;
        if (!queryResults.isEmpty()) {
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.suggest.Suggest

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.