From 0e3b88be35a1e6e318ea1dbf4511dd600429d455 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 15 Mar 2013 15:07:15 +0100 Subject: [PATCH] add CamelCase support to Suggester where missing --- .../search/suggest/SuggestUtils.java | 7 ++-- .../suggest/phrase/PhraseSuggestParser.java | 35 +++++-------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/elasticsearch/search/suggest/SuggestUtils.java b/src/main/java/org/elasticsearch/search/suggest/SuggestUtils.java index 2cd564256ac..4f29abc82b5 100644 --- a/src/main/java/org/elasticsearch/search/suggest/SuggestUtils.java +++ b/src/main/java/org/elasticsearch/search/suggest/SuggestUtils.java @@ -49,7 +49,6 @@ import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.ShingleTokenFilterFactory; import org.elasticsearch.index.analysis.TokenFilterFactory; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.suggest.SuggestionSearchContext.SuggestionContext; public final class SuggestUtils { @@ -189,7 +188,7 @@ public final class SuggestUtils { public static StringDistance resolveDistance(String distanceVal) { if ("internal".equals(distanceVal)) { return DirectSpellChecker.INTERNAL_LEVENSHTEIN; - } else if ("damerau_levenshtein".equals(distanceVal)) { + } else if ("damerau_levenshtein".equals(distanceVal) || "damerauLevenshtein".equals(distanceVal)) { return new LuceneLevenshteinDistance(); } else if ("levenstein".equals(distanceVal)) { return new LevensteinDistance(); @@ -212,12 +211,12 @@ public final class SuggestUtils { suggestion.sort(SuggestUtils.resolveSort(parser.text())); } else if ("string_distance".equals(fieldName) || "stringDistance".equals(fieldName)) { suggestion.stringDistance(SuggestUtils.resolveDistance(parser.text())); - } else if ("max_edits".equals(fieldName) || "maxEdits".equals(fieldName) || "fuzziness".equals(fieldName)) { + } else if ("max_edits".equals(fieldName) || "maxEdits".equals(fieldName)) { suggestion.maxEdits(parser.intValue()); if (suggestion.maxEdits() < 1 || suggestion.maxEdits() > LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE) { throw new ElasticSearchIllegalArgumentException("Illegal max_edits value " + suggestion.maxEdits()); } - } else if ("max_inspections".equals(fieldName)) { + } else if ("max_inspections".equals(fieldName) || "maxInspections".equals(fieldName)) { suggestion.maxInspections(parser.intValue()); } else if ("max_term_freq".equals(fieldName) || "maxTermFreq".equals(fieldName)) { suggestion.maxTermFreq(parser.floatValue()); diff --git a/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestParser.java b/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestParser.java index 30433d5854e..77947223fc9 100644 --- a/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestParser.java +++ b/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestParser.java @@ -18,23 +18,6 @@ */ package org.elasticsearch.search.suggest.phrase; -/* - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ import java.io.IOException; import org.apache.lucene.analysis.Analyzer; @@ -64,7 +47,7 @@ public final class PhraseSuggestParser implements SuggestContextParser { fieldName = parser.currentName(); } else if (token.isValue()) { if (!SuggestUtils.parseSuggestContext(parser, mapperService, fieldName, suggestion)) { - if ("real_word_error_likelihood".equals(fieldName)) { + if ("real_word_error_likelihood".equals(fieldName) || "realWorldErrorLikelihood".equals(fieldName)) { suggestion.setRealWordErrorLikelihood(parser.floatValue()); if (suggestion.realworldErrorLikelyhood() <= 0.0) { throw new ElasticSearchIllegalArgumentException("real_word_error_likelihood must be > 0.0"); @@ -76,25 +59,25 @@ public final class PhraseSuggestParser implements SuggestContextParser { } } else if ("separator".equals(fieldName)) { suggestion.setSeparator(new BytesRef(parser.text())); - } else if ("max_errors".equals(fieldName)) { + } else if ("max_errors".equals(fieldName) || "maxErrors".equals(fieldName)) { suggestion.setMaxErrors(parser.floatValue()); if (suggestion.maxErrors() <= 0.0) { throw new ElasticSearchIllegalArgumentException("max_error must be > 0.0"); } - } else if ("gram_size".equals(fieldName)) { + } else if ("gram_size".equals(fieldName) || "gramSize".equals(fieldName)) { suggestion.setGramSize(parser.intValue()); if (suggestion.gramSize() < 1) { throw new ElasticSearchIllegalArgumentException("gram_size must be >= 1"); } gramSizeSet = true; - } else if ("force_unigrams".equals(fieldName)) { + } else if ("force_unigrams".equals(fieldName) || "forceUnigrams".equals(fieldName)) { suggestion.setRequireUnigram(parser.booleanValue()); } else { throw new ElasticSearchIllegalArgumentException("suggester[phrase] doesn't support field [" + fieldName + "]"); } } } else if (token == Token.START_ARRAY) { - if ("direct_generator".equals(fieldName)) { + if ("direct_generator".equals(fieldName) || "directGenerator".equals(fieldName)) { // for now we only have a single type of generators while ((token = parser.nextToken()) == Token.START_OBJECT) { PhraseSuggestionContext.DirectCandidateGenerator generator = new PhraseSuggestionContext.DirectCandidateGenerator(); @@ -167,17 +150,17 @@ public final class PhraseSuggestParser implements SuggestContextParser { fieldName = parser.currentName(); } if (token.isValue()) { - if ("trigram_lambda".equals(fieldName)) { + if ("trigram_lambda".equals(fieldName) || "trigramLambda".equals(fieldName)) { lambdas[0] = parser.doubleValue(); if (lambdas[0] < 0) { throw new ElasticSearchIllegalArgumentException("trigram_lambda must be positive"); } - } else if ("bigram_lambda".equals(fieldName)) { + } else if ("bigram_lambda".equals(fieldName) || "bigramLambda".equals(fieldName)) { lambdas[1] = parser.doubleValue(); if (lambdas[1] < 0) { throw new ElasticSearchIllegalArgumentException("bigram_lambda must be positive"); } - } else if ("unigram_lambda".equals(fieldName)) { + } else if ("unigram_lambda".equals(fieldName) || "unigramLambda".equals(fieldName)) { lambdas[2] = parser.doubleValue(); if (lambdas[2] < 0) { throw new ElasticSearchIllegalArgumentException("unigram_lambda must be positive"); @@ -224,7 +207,7 @@ public final class PhraseSuggestParser implements SuggestContextParser { } }); - } else if ("stupid_backoff".equals(fieldName)) { + } else if ("stupid_backoff".equals(fieldName) || "stupidBackoff".equals(fieldName)) { ensureNoSmoothing(suggestion); double theDiscount = 0.4; while ((token = parser.nextToken()) != Token.END_OBJECT) {