You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/04/01 09:14:05 UTC
[camel] 05/18: CAMEL-17792: Add doc about the message headers of camel-lucene
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch CAMEL-17792/doc-message-headers
in repository https://gitbox.apache.org/repos/asf/camel.git
commit e61fe3ed5b567d7acd1d7945bc96b9ce2d077fcc
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Thu Mar 31 11:11:40 2022 +0200
CAMEL-17792: Add doc about the message headers of camel-lucene
---
.../org/apache/camel/component/lucene/lucene.json | 4 +++
.../src/main/docs/lucene-component.adoc | 20 ++++---------
.../camel/component/lucene/LuceneConstants.java | 34 ++++++++++++++++++++++
.../camel/component/lucene/LuceneEndpoint.java | 2 +-
.../component/lucene/LuceneQueryProducer.java | 4 +--
.../processor/lucene/LuceneQueryProcessor.java | 5 ++--
.../lucene/LuceneIndexAndQueryProducerIT.java | 10 +++----
.../processor/lucene/LuceneQueryProcessorIT.java | 7 +++--
8 files changed, 58 insertions(+), 28 deletions(-)
diff --git a/components/camel-lucene/src/generated/resources/org/apache/camel/component/lucene/lucene.json b/components/camel-lucene/src/generated/resources/org/apache/camel/component/lucene/lucene.json
index df69160..44f33a7 100644
--- a/components/camel-lucene/src/generated/resources/org/apache/camel/component/lucene/lucene.json
+++ b/components/camel-lucene/src/generated/resources/org/apache/camel/component/lucene/lucene.json
@@ -30,6 +30,10 @@
"autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...]
"config": { "kind": "property", "displayName": "Config", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.lucene.LuceneConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "To use a shared lucene configuration" }
},
+ "headers": {
+ "QUERY": { "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Lucene Query to performed on the index. The query may include\nwildcards and phrases." },
+ "RETURN_LUCENE_DOCS": { "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Set this header to true to include the actual Lucene\ndocumentation when returning hit information." }
+ },
"properties": {
"host": { "kind": "path", "displayName": "Host", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.lucene.LuceneConfiguration", "configurationField": "config", "description": "The URL to the lucene server" },
"operation": { "kind": "path", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.lucene.LuceneOperation", "enum": [ "insert", "query" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.lucene.LuceneConfiguration", "configurationField": "config", "description": "Operation to do such as insert or query." },
diff --git a/components/camel-lucene/src/main/docs/lucene-component.adoc b/components/camel-lucene/src/main/docs/lucene-component.adoc
index fe0e20a..43215d6 100644
--- a/components/camel-lucene/src/main/docs/lucene-component.adoc
+++ b/components/camel-lucene/src/main/docs/lucene-component.adoc
@@ -62,22 +62,12 @@ include::partial$component-endpoint-options.adoc[]
// endpoint options: END
+// component headers: START
+include::partial$component-endpoint-headers.adoc[]
+// component headers: END
== Sending/Receiving Messages to/from the cache
-=== Message Headers
-
-[width="100%",cols="10%,90%",options="header",]
-|=======================================================================
-|Header |Description
-
-|`QUERY` |The Lucene Query to performed on the index. The query may include
-wildcards and phrases
-
-|`RETURN_LUCENE_DOCS` |Set this header to true to include the actual Lucene
-documentation when returning hit information.
-|=======================================================================
-
=== Lucene Producers
This component supports 2 producer endpoints.
@@ -131,7 +121,7 @@ registry.bind("whitespaceAnalyzer", new WhitespaceAnalyzer());
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("direct:start").
- setHeader("QUERY", constant("Seinfeld")).
+ setHeader(LuceneConstants.HEADER_QUERY, constant("Seinfeld")).
to("lucene:searchIndex:query?
analyzer=#whitespaceAnalyzer&indexDir=#whitespace&maxHits=20").
to("direct:next");
@@ -163,7 +153,7 @@ RouteBuilder builder = new RouteBuilder() {
public void configure() {
try {
from("direct:start").
- setHeader("QUERY", constant("Rodney Dangerfield")).
+ setHeader(LuceneConstants.HEADER_QUERY, constant("Rodney Dangerfield")).
process(new LuceneQueryProcessor("target/stdindexDir", analyzer, null, 20)).
to("direct:next");
} catch (Exception e) {
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
new file mode 100644
index 0000000..bbbf416
--- /dev/null
+++ b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConstants.java
@@ -0,0 +1,34 @@
+/*
+ * 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.camel.spi.Metadata;
+
+public final class LuceneConstants {
+
+ @Metadata(description = "The Lucene Query to performed on the index. The query may include\n" +
+ "wildcards and phrases.",
+ javaType = "String")
+ public static final String HEADER_QUERY = "QUERY";
+ @Metadata(description = "Set this header to true to include the actual Lucene\n" +
+ "documentation when returning hit information.",
+ javaType = "String")
+ public static final String HEADER_RETURN_LUCENE_DOCS = "RETURN_LUCENE_DOCS";
+
+ private LuceneConstants() {
+ }
+}
diff --git a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java
index 6631596..2ef4f04 100644
--- a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java
+++ b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java
@@ -29,7 +29,7 @@ import org.apache.camel.support.DefaultEndpoint;
* Perform inserts or queries against Apache Lucene databases.
*/
@UriEndpoint(firstVersion = "2.2.0", scheme = "lucene", title = "Lucene", syntax = "lucene:host:operation", producerOnly = true,
- category = { Category.DATABASE, Category.SEARCH })
+ category = { Category.DATABASE, Category.SEARCH }, headersClass = LuceneConstants.class)
public class LuceneEndpoint extends DefaultEndpoint {
@UriParam
LuceneConfiguration config;
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 7a7e9db..9da9bea 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
@@ -56,8 +56,8 @@ public class LuceneQueryProducer extends DefaultProducer {
public void process(Exchange exchange) throws Exception {
Hits hits;
- String phrase = exchange.getIn().getHeader("QUERY", String.class);
- String returnLuceneDocs = exchange.getIn().getHeader("RETURN_LUCENE_DOCS", String.class);
+ String phrase = exchange.getIn().getHeader(LuceneConstants.HEADER_QUERY, String.class);
+ String returnLuceneDocs = exchange.getIn().getHeader(LuceneConstants.HEADER_RETURN_LUCENE_DOCS, String.class);
boolean isReturnLuceneDocs = returnLuceneDocs != null && returnLuceneDocs.equalsIgnoreCase("true");
if (phrase != null) {
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 8caae9f..00e5e02 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
@@ -20,6 +20,7 @@ import java.io.File;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
+import org.apache.camel.component.lucene.LuceneConstants;
import org.apache.camel.component.lucene.LuceneSearcher;
import org.apache.camel.processor.lucene.support.Hits;
import org.apache.lucene.analysis.Analyzer;
@@ -45,8 +46,8 @@ public class LuceneQueryProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
Hits hits;
- String phrase = exchange.getIn().getHeader("QUERY", String.class);
- String returnLuceneDocs = exchange.getIn().getHeader("RETURN_LUCENE_DOCS", String.class);
+ String phrase = exchange.getIn().getHeader(LuceneConstants.HEADER_QUERY, String.class);
+ String returnLuceneDocs = exchange.getIn().getHeader(LuceneConstants.HEADER_RETURN_LUCENE_DOCS, String.class);
boolean isReturnLuceneDocs = returnLuceneDocs != null && returnLuceneDocs.equalsIgnoreCase("true");
if (phrase != null) {
diff --git a/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerIT.java b/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerIT.java
index a633f4a..a72f841 100644
--- a/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerIT.java
+++ b/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerIT.java
@@ -86,7 +86,7 @@ public class LuceneIndexAndQueryProducerIT extends CamelTestSupport {
// Set the property of the charset encoding
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
Message in = exchange.getIn();
- in.setHeader("QUERY", "");
+ in.setHeader(LuceneConstants.HEADER_QUERY, "");
}
});
}
@@ -122,7 +122,7 @@ public class LuceneIndexAndQueryProducerIT extends CamelTestSupport {
context.addRoutes(new RouteBuilder() {
public void configure() {
- from("direct:start").setHeader("QUERY", constant("Seinfeld"))
+ from("direct:start").setHeader(LuceneConstants.HEADER_QUERY, constant("Seinfeld"))
.to("lucene:searchIndex:query?analyzer=#whitespaceAnalyzer&indexDir=#whitespace&maxHits=20")
.to("direct:next");
@@ -158,7 +158,7 @@ public class LuceneIndexAndQueryProducerIT extends CamelTestSupport {
context.addRoutes(new RouteBuilder() {
public void configure() {
- from("direct:start").setHeader("QUERY", constant("Grouc?? Marx"))
+ from("direct:start").setHeader(LuceneConstants.HEADER_QUERY, constant("Grouc?? Marx"))
.to("lucene:searchIndex:query?analyzer=#stdAnalyzer&indexDir=#std&maxHits=20").to("direct:next");
from("direct:next").process(new Processor() {
@@ -192,8 +192,8 @@ public class LuceneIndexAndQueryProducerIT extends CamelTestSupport {
context.addRoutes(new RouteBuilder() {
public void configure() {
- from("direct:start").setHeader("QUERY", constant("Grouc?? Marx"))
- .setHeader("RETURN_LUCENE_DOCS", constant("true"))
+ from("direct:start").setHeader(LuceneConstants.HEADER_QUERY, constant("Grouc?? Marx"))
+ .setHeader(LuceneConstants.HEADER_RETURN_LUCENE_DOCS, constant("true"))
.to("lucene:searchIndex:query?analyzer=#stdAnalyzer&indexDir=#std&maxHits=20").to("direct:next");
from("direct:next").process(new Processor() {
diff --git a/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorIT.java b/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorIT.java
index 34e897d..9c2adcb 100644
--- a/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorIT.java
+++ b/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorIT.java
@@ -20,6 +20,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.lucene.LuceneConstants;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.processor.lucene.support.Hits;
import org.apache.camel.test.junit5.CamelTestSupport;
@@ -44,7 +45,7 @@ public class LuceneQueryProcessorIT extends CamelTestSupport {
// Set the property of the charset encoding
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
Message in = exchange.getIn();
- in.setHeader("QUERY", "");
+ in.setHeader(LuceneConstants.HEADER_QUERY, "");
}
});
}
@@ -59,7 +60,7 @@ public class LuceneQueryProcessorIT extends CamelTestSupport {
public void configure() {
try {
- from("direct:start").setHeader("QUERY", constant("Rodney Dangerfield"))
+ from("direct:start").setHeader(LuceneConstants.HEADER_QUERY, constant("Rodney Dangerfield"))
.process(new LuceneQueryProcessor("target/stdindexDir", analyzer, null, 20)).to("direct:next");
} catch (Exception e) {
LOG.warn("Unhandled exception: {}", e.getMessage(), e);
@@ -101,7 +102,7 @@ public class LuceneQueryProcessorIT extends CamelTestSupport {
public void configure() {
try {
- from("direct:start").setHeader("QUERY", constant("Carl*"))
+ from("direct:start").setHeader(LuceneConstants.HEADER_QUERY, constant("Carl*"))
.process(new LuceneQueryProcessor("target/simpleindexDir", analyzer, null, 20))
.to("direct:next");
} catch (Exception e) {