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 2020/02/15 09:46:10 UTC

[camel] 01/04: Remove not used cruft from camel-lucene

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 385ba74e32106c3086aa1617db9208e96e222e58
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Feb 15 10:29:29 2020 +0100

    Remove not used cruft from camel-lucene
---
 .../component/lucene/LuceneConfiguration.java      | 44 +++++-----------------
 .../camel/component/lucene/LuceneConstants.java    | 23 -----------
 .../component/lucene/LuceneQueryProducer.java      |  4 +-
 .../camel/component/lucene/LuceneSearcher.java     |  9 ++---
 .../processor/lucene/LuceneQueryProcessor.java     | 13 +------
 .../lucene/LuceneIndexAndQueryProducerTest.java    |  7 +---
 6 files changed, 18 insertions(+), 82 deletions(-)

diff --git a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java
index 17164ad..831d042 100644
--- a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java
+++ b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java
@@ -27,13 +27,11 @@ import org.apache.camel.spi.UriParams;
 import org.apache.camel.spi.UriPath;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.util.Version;
 
 @UriParams
 public class LuceneConfiguration {
-    private URI uri;
-    private String authority;
-    private Version luceneVersion = LuceneConstants.LUCENE_VERSION;
+    private transient URI uri;
+    private transient String authority;
 
     @UriPath @Metadata(required = true)
     private String host;
@@ -61,10 +59,10 @@ public class LuceneConfiguration {
         if (!protocol.equalsIgnoreCase("lucene")) {
             throw new IllegalArgumentException("Unrecognized Lucene protocol: " + protocol + " for uri: " + uri);
         }
-        setUri(uri);
-        setAuthority(uri.getAuthority());
+        this.uri = uri;
+        this.authority = uri.getAuthority();
         if (!isValidAuthority()) {
-            throw new URISyntaxException(uri.toASCIIString(), 
+            throw new URISyntaxException(uri.toASCIIString(),
                     "Incorrect URI syntax and/or Operation specified for the Lucene endpoint."
                     + " Please specify the syntax as \"lucene:[Endpoint Name]:[Operation]?[Query]\"");
         }
@@ -87,15 +85,15 @@ public class LuceneConfiguration {
     }
     
     private boolean isValidAuthority() throws URISyntaxException {
-        if ((!authority.contains(":")) 
-            || ((authority.split(":")[0]) == null)  
+        if ((!authority.contains(":"))
+            || ((authority.split(":")[0]) == null)
             || ((!authority.split(":")[1].equalsIgnoreCase("insert")) && (!authority.split(":")[1].equalsIgnoreCase("query")))) {
             return false;
         }
         return true;
-        
+
     }
-    
+
     private String retrieveTokenFromAuthority(String token) throws URISyntaxException {
         String retval;
         
@@ -107,14 +105,6 @@ public class LuceneConfiguration {
         return retval;
     }
 
-    public URI getUri() {
-        return uri;
-    }
-
-    public void setUri(URI uri) {
-        this.uri = uri;
-    }
-
     public String getHost() {
         return host;
     }
@@ -137,14 +127,6 @@ public class LuceneConfiguration {
         this.operation = operation;
     }
 
-    public String getAuthority() {
-        return authority;
-    }
-
-    public void setAuthority(String authority) {
-        this.authority = authority;
-    }
-
     public File getSrcDir() {
         return srcDir;
     }
@@ -190,13 +172,5 @@ public class LuceneConfiguration {
     public void setMaxHits(int maxHits) {
         this.maxHits = maxHits;
     }
-    
-    public void setLuceneVersion(Version luceneVersion) {
-        this.luceneVersion = luceneVersion;
-    }
 
-    public Version getLuceneVersion() {
-        return luceneVersion;
-    }
-    
 }
diff --git a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConstants.java b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConstants.java
deleted file mode 100644
index 31e8a4b..0000000
--- a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConstants.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * 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
- *
- * 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.
- */
-package org.apache.camel.component.lucene;
-
-import org.apache.lucene.util.Version;
-
-public interface LuceneConstants {
-    Version LUCENE_VERSION = Version.LUCENE_7_2_1;
-}
diff --git a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java
index 293d0c8..15a8655 100644
--- a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java
+++ b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java
@@ -58,11 +58,11 @@ public class LuceneQueryProducer extends DefaultProducer {
         
         String phrase = exchange.getIn().getHeader("QUERY", String.class);
         String returnLuceneDocs = exchange.getIn().getHeader("RETURN_LUCENE_DOCS", String.class);
-        boolean isReturnLuceneDocs = (returnLuceneDocs != null && returnLuceneDocs.equalsIgnoreCase("true")) ? true : false;
+        boolean isReturnLuceneDocs = returnLuceneDocs != null && returnLuceneDocs.equalsIgnoreCase("true");
 
         if (phrase != null) {
             searcher.open(indexDirectory, analyzer);
-            hits = searcher.search(phrase, maxNumberOfHits, totalHitsThreshold, config.getLuceneVersion(), isReturnLuceneDocs);
+            hits = searcher.search(phrase, maxNumberOfHits, totalHitsThreshold, isReturnLuceneDocs);
         } else {
             throw new IllegalArgumentException("SearchPhrase for LucenePhraseQuerySearcher not set. Set the Header value: QUERY");
         }            
diff --git a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java
index 25a0f80..d06f7ad 100644
--- a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java
+++ b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java
@@ -32,7 +32,6 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TopScoreDocCollector;
 import org.apache.lucene.store.NIOFSDirectory;
-import org.apache.lucene.util.Version;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -59,13 +58,13 @@ public class LuceneSearcher {
     }
     
     public Hits search(String searchPhrase, int maxNumberOfHits, int totalHitsThreshold) throws Exception {
-        return search(searchPhrase, maxNumberOfHits, totalHitsThreshold, LuceneConstants.LUCENE_VERSION, false);
+        return search(searchPhrase, maxNumberOfHits, totalHitsThreshold, false);
     }
 
-    public Hits search(String searchPhrase, int maxNumberOfHits, int totalHitsThreshold, Version luceneVersion, boolean returnLuceneDocs) throws Exception {
+    public Hits search(String searchPhrase, int maxNumberOfHits, int totalHitsThreshold, boolean returnLuceneDocs) throws Exception {
         Hits searchHits = new Hits();
 
-        int numberOfHits = doSearch(searchPhrase, maxNumberOfHits, totalHitsThreshold, luceneVersion);
+        int numberOfHits = doSearch(searchPhrase, maxNumberOfHits, totalHitsThreshold);
         searchHits.setNumberOfHits(numberOfHits);
 
         for (ScoreDoc hit : hits) {
@@ -83,7 +82,7 @@ public class LuceneSearcher {
         return searchHits;
     }
                 
-    private int doSearch(String searchPhrase, int maxNumberOfHits, int totalHitsThreshold, Version luceneVersion) throws NullPointerException, ParseException, IOException {
+    private int doSearch(String searchPhrase, int maxNumberOfHits, int totalHitsThreshold) throws NullPointerException, ParseException, IOException {
         LOG.trace("*** Search Phrase: {} ***", searchPhrase);
 
         QueryParser parser = new QueryParser("contents", analyzer);
diff --git a/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java b/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java
index 3a78605..6cde4aa 100644
--- a/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java
+++ b/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java
@@ -34,7 +34,6 @@ public class LuceneQueryProcessor implements Processor {
     private String searchPhrase;
     private int maxNumberOfHits;
     private int totalHitsThreshold;
-    private Version luceneVersion;
 
     public LuceneQueryProcessor(String indexDirectoryPath, Analyzer analyzer, String defaultSearchPhrase, int maxNumberOfHits, int totalHitsThreshold) {
         this.setAnalyzer(analyzer);
@@ -49,12 +48,12 @@ public class LuceneQueryProcessor implements Processor {
 
         String phrase = exchange.getIn().getHeader("QUERY", String.class);
         String returnLuceneDocs = exchange.getIn().getHeader("RETURN_LUCENE_DOCS", String.class);
-        boolean isReturnLuceneDocs = (returnLuceneDocs != null && returnLuceneDocs.equalsIgnoreCase("true")) ? true : false;
+        boolean isReturnLuceneDocs = returnLuceneDocs != null && returnLuceneDocs.equalsIgnoreCase("true");
 
         if (phrase != null) {
             searcher = new LuceneSearcher();
             searcher.open(indexDirectory, analyzer);
-            hits = searcher.search(phrase, maxNumberOfHits, totalHitsThreshold, luceneVersion, isReturnLuceneDocs);
+            hits = searcher.search(phrase, maxNumberOfHits, totalHitsThreshold, isReturnLuceneDocs);
         } else {
             throw new IllegalArgumentException("SearchPhrase for LuceneQueryProcessor not set. Set the Header value: QUERY");
         }
@@ -102,14 +101,6 @@ public class LuceneQueryProcessor implements Processor {
         this.maxNumberOfHits = maxNumberOfHits;
     }
 
-    public void setLuceneVersion(Version luceneVersion) {
-        this.luceneVersion = luceneVersion;
-    }
-
-    public Version getLuceneVersion() {
-        return luceneVersion;
-    }
-
     public int getTotalHitsThreshold() {
         return totalHitsThreshold;
     }
diff --git a/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java b/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java
index cbcf22b..efbd8e6 100644
--- a/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java
+++ b/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java
@@ -210,12 +210,7 @@ public class LuceneIndexAndQueryProducerTest extends CamelTestSupport {
                 from("direct:next").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         Hits hits = exchange.getIn().getBody(Hits.class);
-                        try {
-                            printResults(hits);
-                        } catch (Exception e) {
-                            LOG.error(e.getMessage());
-                            exchange.getOut().setBody(null);
-                        }
+                        printResults(hits);
                     }
 
                     private void printResults(Hits hits) throws Exception {