exhaust object to allow subsequent objects to be parsed correctly

This commit is contained in:
Simon Willnauer 2013-03-06 15:34:59 +01:00
parent 1f217f6a7b
commit 12a2808168
1 changed files with 82 additions and 80 deletions

View File

@ -159,9 +159,6 @@ public final class PhraseSuggestParser implements SuggestContextParser {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
fieldName = parser.currentName();
break;
}
}
if ("linear".equals(fieldName)) {
ensureNoSmoothing(suggestion);
final double[] lambdas = new double[3];
@ -186,7 +183,8 @@ public final class PhraseSuggestParser implements SuggestContextParser {
throw new ElasticSearchIllegalArgumentException("unigram_lambda must be positive");
}
} else {
throw new ElasticSearchIllegalArgumentException("suggester[phrase][smoothing][linear] doesn't support field [" + fieldName + "]");
throw new ElasticSearchIllegalArgumentException(
"suggester[phrase][smoothing][linear] doesn't support field [" + fieldName + "]");
}
}
}
@ -218,9 +216,10 @@ public final class PhraseSuggestParser implements SuggestContextParser {
}
}
final double alpha = theAlpha;
suggestion.setModel( new WordScorer.WordScorerFactory() {
suggestion.setModel(new WordScorer.WordScorerFactory() {
@Override
public WordScorer newScorer(IndexReader reader, String field, double realWordLikelyhood, BytesRef separator) throws IOException {
public WordScorer newScorer(IndexReader reader, String field, double realWordLikelyhood, BytesRef separator)
throws IOException {
return new LaplaceScorer(reader, field, realWordLikelyhood, separator, alpha);
}
});
@ -237,9 +236,10 @@ public final class PhraseSuggestParser implements SuggestContextParser {
}
}
final double discount = theDiscount;
suggestion.setModel( new WordScorer.WordScorerFactory() {
suggestion.setModel(new WordScorer.WordScorerFactory() {
@Override
public WordScorer newScorer(IndexReader reader, String field, double realWordLikelyhood, BytesRef separator) throws IOException {
public WordScorer newScorer(IndexReader reader, String field, double realWordLikelyhood, BytesRef separator)
throws IOException {
return new StupidBackoffScorer(reader, field, realWordLikelyhood, separator, discount);
}
});
@ -248,6 +248,8 @@ public final class PhraseSuggestParser implements SuggestContextParser {
throw new ElasticSearchIllegalArgumentException("suggester[phrase] doesn't support object field [" + fieldName + "]");
}
}
}
}
private void ensureNoSmoothing(PhraseSuggestionContext suggestion) {
if (suggestion.model() != null) {