Package org.elasticsearch.search.suggest.SuggestionSearchContext

Examples of org.elasticsearch.search.suggest.SuggestionSearchContext.SuggestionContext


                    throw new ElasticsearchIllegalArgumentException("[suggest] does not support [" + fieldName + "]");
                }
            } else if (token == XContentParser.Token.START_OBJECT) {
                String suggestionName = fieldName;
                BytesRef suggestText = null;
                SuggestionContext suggestionContext = null;

                while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                    if (token == XContentParser.Token.FIELD_NAME) {
                        fieldName = parser.currentName();
                    } else if (token.isValue()) {
                        if ("text".equals(fieldName)) {
                            suggestText = parser.utf8Bytes();
                        } else {
                            throw new ElasticsearchIllegalArgumentException("[suggest] does not support [" + fieldName + "]");
                        }
                    } else if (token == XContentParser.Token.START_OBJECT) {
                        if (suggestionName == null) {
                            throw new ElasticsearchIllegalArgumentException("Suggestion must have name");
                        }
                        if (suggesters.get(fieldName) == null) {
                            throw new ElasticsearchIllegalArgumentException("Suggester[" + fieldName + "] not supported");
                        }
                        final SuggestContextParser contextParser = suggesters.get(fieldName).getContextParser();
                        suggestionContext = contextParser.parse(parser, mapperService);
                    }
                }
                if (suggestionContext != null) {
                    suggestionContext.setText(suggestText);
                    suggestionContexts.put(suggestionName, suggestionContext);
                }

            }
        }

        for (Map.Entry<String, SuggestionContext> entry : suggestionContexts.entrySet()) {
            String suggestionName = entry.getKey();
            SuggestionContext suggestionContext = entry.getValue();

            suggestionContext.setShard(shardId);
            suggestionContext.setIndex(index);
            SuggestUtils.verifySuggestion(mapperService, globalText, suggestionContext);
            suggestionSearchContext.addSuggestion(suggestionName, suggestionContext);
        }

        return suggestionSearchContext;
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.suggest.SuggestionSearchContext.SuggestionContext

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.