You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/12/23 12:45:23 UTC

[3/8] camel git commit: CAMEL-9434: camel-catalog - did you mean

CAMEL-9434: camel-catalog - did you mean


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2e502e44
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2e502e44
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2e502e44

Branch: refs/heads/master
Commit: 2e502e446713650c46983dc4a153b7c37d288d11
Parents: 758327f
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 23 12:41:54 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 23 12:41:54 2015 +0100

----------------------------------------------------------------------
 apache-camel/pom.xml                                    |  4 ++++
 apache-camel/src/main/descriptors/common-bin.xml        |  1 +
 parent/pom.xml                                          |  5 +++++
 platforms/catalog-lucene/pom.xml                        |  8 --------
 .../camel/catalog/lucene/LuceneSuggestionStrategy.java  | 10 ++++++++--
 .../org/apache/camel/catalog/SuggestionStrategy.java    | 12 ++++++------
 6 files changed, 24 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2e502e44/apache-camel/pom.xml
----------------------------------------------------------------------
diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml
index 61fcee9..6a54092 100644
--- a/apache-camel/pom.xml
+++ b/apache-camel/pom.xml
@@ -898,6 +898,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-catalog-lucene</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-commands-core</artifactId>
     </dependency>
     <dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/2e502e44/apache-camel/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml
index 09585d4..9d2e447 100644
--- a/apache-camel/src/main/descriptors/common-bin.xml
+++ b/apache-camel/src/main/descriptors/common-bin.xml
@@ -235,6 +235,7 @@
         <include>org.apache.camel:camel-zipfile</include>
         <include>org.apache.camel:camel-zookeeper</include>
         <include>org.apache.camel:camel-catalog</include>
+        <include>org.apache.camel:camel-catalog-lucene</include>
         <include>org.apache.camel:camel-commands-core</include>
         <include>org.apache.camel:camel-commands-jolokia</include>
         <include>org.apache.camel:camel-commands-spring-boot</include>

http://git-wip-us.apache.org/repos/asf/camel/blob/2e502e44/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index c05db62..f2e3db2 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1700,6 +1700,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
+        <artifactId>camel-catalog-lucene</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
         <artifactId>camel-commands-core</artifactId>
         <version>${project.version}</version>
       </dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/2e502e44/platforms/catalog-lucene/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/catalog-lucene/pom.xml b/platforms/catalog-lucene/pom.xml
index d211db9..1eb9bff 100644
--- a/platforms/catalog-lucene/pom.xml
+++ b/platforms/catalog-lucene/pom.xml
@@ -53,14 +53,6 @@
       <version>${lucene-version}</version>
     </dependency>
 
-    <!-- testing -->
-    <dependency>
-      <groupId>com.fasterxml.jackson.core</groupId>
-      <artifactId>jackson-databind</artifactId>
-      <version>${jackson2-version}</version>
-      <scope>test</scope>
-    </dependency>
-
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>

http://git-wip-us.apache.org/repos/asf/camel/blob/2e502e44/platforms/catalog-lucene/src/main/java/org/apache/camel/catalog/lucene/LuceneSuggestionStrategy.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-lucene/src/main/java/org/apache/camel/catalog/lucene/LuceneSuggestionStrategy.java b/platforms/catalog-lucene/src/main/java/org/apache/camel/catalog/lucene/LuceneSuggestionStrategy.java
index e8cae13..5ed183f 100644
--- a/platforms/catalog-lucene/src/main/java/org/apache/camel/catalog/lucene/LuceneSuggestionStrategy.java
+++ b/platforms/catalog-lucene/src/main/java/org/apache/camel/catalog/lucene/LuceneSuggestionStrategy.java
@@ -28,11 +28,16 @@ import org.apache.lucene.store.RAMDirectory;
 
 /**
  * Apache Lucene based {@link SuggestionStrategy}.
+ * <p/>
+ * This is a simple implementation using in-memory directory and no state.
  */
 public class LuceneSuggestionStrategy implements SuggestionStrategy {
 
+    private int maxSuggestions = 5;
+
     @Override
-    public String[] suggestEndpointOptions(Set<String> names, String option) {
+    public String[] suggestEndpointOptions(Set<String> names, String unknownOption) {
+        // each option must be on a separate line in a String
         StringBuilder sb = new StringBuilder();
         for (String name : names) {
             sb.append(name);
@@ -43,12 +48,13 @@ public class LuceneSuggestionStrategy implements SuggestionStrategy {
         try {
             PlainTextDictionary words = new PlainTextDictionary(reader);
 
+            // use in-memory lucene spell checker to make the suggestions
             RAMDirectory dir = new RAMDirectory();
             SpellChecker checker = new SpellChecker(dir);
             checker.indexDictionary(words, new IndexWriterConfig(new StandardAnalyzer()), false);
 
             // suggest up to 5 names
-            return checker.suggestSimilar(option, 5);
+            return checker.suggestSimilar(unknownOption, maxSuggestions);
         } catch (Exception e) {
             // ignore
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/2e502e44/platforms/catalog/src/main/java/org/apache/camel/catalog/SuggestionStrategy.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/SuggestionStrategy.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/SuggestionStrategy.java
index 90faa49..9b6dfce 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/SuggestionStrategy.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/SuggestionStrategy.java
@@ -5,9 +5,9 @@
  * The ASF 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
- *
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
  * 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.
@@ -26,9 +26,9 @@ public interface SuggestionStrategy {
     /**
      * Provides a list of valid option names for a did you mean function.
      *
-     * @param names  valid names
-     * @param option unknown option name
+     * @param names         valid names
+     * @param unknownOption unknown option name
      * @return a list of suggested names (did you mean)
      */
-    String[] suggestEndpointOptions(Set<String> names, String option);
+    String[] suggestEndpointOptions(Set<String> names, String unknownOption);
 }