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 2010/01/05 08:19:43 UTC
svn commit: r895924 [1/2] - in /camel/trunk: apache-camel/
apache-camel/src/main/descriptors/ components/ components/camel-lucene/
components/camel-lucene/src/ components/camel-lucene/src/main/
components/camel-lucene/src/main/java/ components/camel-lu...
Author: davsclaus
Date: Tue Jan 5 07:19:41 2010
New Revision: 895924
URL: http://svn.apache.org/viewvc?rev=895924&view=rev
Log:
CAMEL-1472: Added new camel-lucene component contributed by Ashwin Karpe. Thanks a lot, keep them coming.
Added:
camel/trunk/components/camel-lucene/
camel/trunk/components/camel-lucene/pom.xml (with props)
camel/trunk/components/camel-lucene/src/
camel/trunk/components/camel-lucene/src/main/
camel/trunk/components/camel-lucene/src/main/java/
camel/trunk/components/camel-lucene/src/main/java/org/
camel/trunk/components/camel-lucene/src/main/java/org/apache/
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneComponent.java (with props)
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java (with props)
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java (with props)
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexProducer.java (with props)
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java (with props)
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java (with props)
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java (with props)
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java (with props)
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hit.java (with props)
camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hits.java (with props)
camel/trunk/components/camel-lucene/src/main/resources/
camel/trunk/components/camel-lucene/src/main/resources/META-INF/
camel/trunk/components/camel-lucene/src/main/resources/META-INF/LICENSE.txt (with props)
camel/trunk/components/camel-lucene/src/main/resources/META-INF/NOTICE.txt (with props)
camel/trunk/components/camel-lucene/src/main/resources/META-INF/services/
camel/trunk/components/camel-lucene/src/main/resources/META-INF/services/org/
camel/trunk/components/camel-lucene/src/main/resources/META-INF/services/org/apache/
camel/trunk/components/camel-lucene/src/main/resources/META-INF/services/org/apache/camel/
camel/trunk/components/camel-lucene/src/main/resources/META-INF/services/org/apache/camel/component/
camel/trunk/components/camel-lucene/src/main/resources/META-INF/services/org/apache/camel/component/lucene
camel/trunk/components/camel-lucene/src/test/
camel/trunk/components/camel-lucene/src/test/java/
camel/trunk/components/camel-lucene/src/test/java/org/
camel/trunk/components/camel-lucene/src/test/java/org/apache/
camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/
camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/component/
camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/
camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java (with props)
camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/processor/
camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/
camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorTest.java (with props)
camel/trunk/components/camel-lucene/src/test/resources/
camel/trunk/components/camel-lucene/src/test/resources/log4j.properties (with props)
camel/trunk/components/camel-lucene/src/test/resources/sources/
camel/trunk/components/camel-lucene/src/test/resources/sources/quote.txt (with props)
Modified:
camel/trunk/apache-camel/pom.xml
camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
camel/trunk/components/pom.xml
camel/trunk/parent/pom.xml
Modified: camel/trunk/apache-camel/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/pom.xml?rev=895924&r1=895923&r2=895924&view=diff
==============================================================================
--- camel/trunk/apache-camel/pom.xml (original)
+++ camel/trunk/apache-camel/pom.xml Tue Jan 5 07:19:41 2010
@@ -168,6 +168,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-lucene</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-mail</artifactId>
</dependency>
<dependency>
Modified: camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/src/main/descriptors/common-bin.xml?rev=895924&r1=895923&r2=895924&view=diff
==============================================================================
--- camel/trunk/apache-camel/src/main/descriptors/common-bin.xml (original)
+++ camel/trunk/apache-camel/src/main/descriptors/common-bin.xml Tue Jan 5 07:19:41 2010
@@ -64,6 +64,7 @@
<include>org.apache.camel:camel-jpa</include>
<include>org.apache.camel:camel-juel</include>
<include>org.apache.camel:camel-jxpath</include>
+ <include>org.apache.camel:camel-lucene</include>
<include>org.apache.camel:camel-mail</include>
<include>org.apache.camel:camel-mina</include>
<include>org.apache.camel:camel-msv</include>
Added: camel/trunk/components/camel-lucene/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/pom.xml?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/pom.xml (added)
+++ camel/trunk/components/camel-lucene/pom.xml Tue Jan 5 07:19:41 2010
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+ <!--
+ 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.
+ -->
+
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-lucene</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Lucene</name>
+ <description>Camel Lucene based search component</description>
+
+ <properties>
+ <camel.osgi.export.pkg>
+ org.apache.camel.component.lucene.*,
+ org.apache.camel.processor.lucene.*
+ </camel.osgi.export.pkg>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-core</artifactId>
+ <version>${lucene-version}</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-clean-plugin</artifactId>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>${basedir}/res</directory>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: camel/trunk/components/camel-lucene/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/pom.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-lucene/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneComponent.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneComponent.java (added)
+++ camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneComponent.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,47 @@
+/**
+ * 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 java.net.URI;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+public class LuceneComponent extends DefaultComponent {
+ LuceneConfiguration config;
+
+ public LuceneComponent() {
+ config = new LuceneConfiguration();
+ }
+
+ public LuceneComponent(CamelContext context) {
+ super(context);
+ config = new LuceneConfiguration();
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters)
+ throws Exception {
+ config.parseURI(new URI(uri), parameters, this);
+ LuceneEndpoint luceneEndpoint = new LuceneEndpoint(uri, this, config);
+ setProperties(luceneEndpoint.getConfig(), parameters);
+ return luceneEndpoint;
+ }
+
+}
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneComponent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java (added)
+++ camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,168 @@
+/**
+ * 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 java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+
+public class LuceneConfiguration {
+ private static final transient Log LOG = LogFactory.getLog(LuceneConfiguration.class);
+ private URI uri;
+ private String protocolType;
+ private String authority;
+ private String host;
+ private String operation;
+ private File sourceDirectory;
+ private File indexDirectory;
+ private Analyzer analyzer;
+ private int maxHits;
+
+ public LuceneConfiguration() {
+ }
+
+ public LuceneConfiguration(URI uri) throws Exception {
+ this();
+ this.uri = uri;
+ }
+
+ public void parseURI(URI uri, Map<String, Object> parameters, LuceneComponent component) throws Exception {
+ String protocol = uri.getScheme();
+
+ if (!protocol.equalsIgnoreCase("lucene")) {
+ throw new IllegalArgumentException("Unrecognized Lucene protocol: " + protocol + " for uri: " + uri);
+ }
+ setUri(uri);
+ setAuthority(uri.getAuthority());
+ if (!isValidAuthority()) {
+ 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]\"");
+ }
+ setHost(retrieveTokenFromAuthority("hostname"));
+ setOperation(retrieveTokenFromAuthority("operation"));
+
+ sourceDirectory = component.resolveAndRemoveReferenceParameter(
+ parameters, "srcDir", File.class, null);
+ indexDirectory = component.resolveAndRemoveReferenceParameter(
+ parameters, "indexDir", File.class, new File("file:///./indexDirectory"));
+ analyzer = component.resolveAndRemoveReferenceParameter(
+ parameters, "analyzer", Analyzer.class, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
+
+ setMaxHits(component.getAndRemoveParameter(parameters, "maxHits", Integer.class, 10));
+ }
+
+ private boolean isValidAuthority() throws URISyntaxException {
+ 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;
+
+ if (token.equalsIgnoreCase("hostname")) {
+ retval = uri.getAuthority().split(":")[0];
+ } else {
+ retval = uri.getAuthority().split(":")[1];
+ }
+ return retval;
+ }
+
+ public URI getUri() {
+ return uri;
+ }
+
+ public void setUri(URI uri) {
+ this.uri = uri;
+ }
+
+ public String getProtocolType() {
+ return protocolType;
+ }
+
+ public void setProtocolType(String protocolType) {
+ this.protocolType = protocolType;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public String getOperation() {
+ return operation;
+ }
+
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+
+ public String getAuthority() {
+ return authority;
+ }
+
+ public void setAuthority(String authority) {
+ this.authority = authority;
+ }
+
+ public File getSourceDirectory() {
+ return sourceDirectory;
+ }
+
+ public void setSourceDirectory(File sourceDirectory) {
+ this.sourceDirectory = sourceDirectory;
+ }
+
+ public File getIndexDirectory() {
+ return indexDirectory;
+ }
+
+ public void setIndexDirectory(File indexDirectory) {
+ this.indexDirectory = indexDirectory;
+ }
+
+ public Analyzer getAnalyzer() {
+ return analyzer;
+ }
+
+ public void setAnalyzer(Analyzer analyzer) {
+ this.analyzer = analyzer;
+ }
+
+ public int getMaxHits() {
+ return maxHits;
+ }
+
+ public void setMaxHits(int maxHits) {
+ this.maxHits = maxHits;
+ }
+
+}
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java (added)
+++ camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,79 @@
+/**
+ * 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.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+
+public class LuceneEndpoint extends DefaultEndpoint {
+ LuceneConfiguration config;
+ LuceneIndexer indexer;
+ boolean insertFlag;
+
+ public LuceneEndpoint() {
+ super();
+ }
+
+ public LuceneEndpoint(String endpointUri, CamelContext camelContext) {
+ super(endpointUri, camelContext);
+ }
+
+ public LuceneEndpoint(String endpointUri, Component component) {
+ super(endpointUri, component);
+ }
+
+ public LuceneEndpoint(String endpointUri) {
+ super(endpointUri);
+ }
+
+ public LuceneEndpoint(String endpointUri, LuceneComponent component, LuceneConfiguration config) throws Exception {
+ this(endpointUri, component);
+ this.config = config;
+ if (config.getOperation().equalsIgnoreCase("insert")) {
+ this.indexer = new LuceneIndexer(config.getSourceDirectory(), config.getIndexDirectory(), config.getAnalyzer());
+ insertFlag = true;
+ }
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("Consumer not supported for Lucene endpoint");
+ }
+
+ public Producer createProducer() throws Exception {
+ if (!insertFlag) {
+ return new LuceneQueryProducer(this, this.config);
+ }
+ return new LuceneIndexProducer(this, this.config, indexer);
+ }
+
+ public LuceneConfiguration getConfig() {
+ return config;
+ }
+
+ public void setConfig(LuceneConfiguration config) {
+ this.config = config;
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+}
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexProducer.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexProducer.java (added)
+++ camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexProducer.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,62 @@
+/**
+ * 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.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+
+public class LuceneIndexProducer extends DefaultProducer {
+ LuceneConfiguration config;
+ LuceneIndexer indexer;
+
+ public LuceneIndexProducer(Endpoint endpoint, LuceneConfiguration config, LuceneIndexer indexer) throws Exception {
+ super(endpoint);
+ this.config = config;
+ this.indexer = indexer;
+ }
+
+ public void start() throws Exception {
+ super.doStart();
+ }
+
+ public void stop() throws Exception {
+ this.indexer.getNiofsDirectory().close();
+ super.doStop();
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ indexer.index(exchange);
+ }
+
+ public LuceneConfiguration getConfig() {
+ return config;
+ }
+
+ public void setConfig(LuceneConfiguration config) {
+ this.config = config;
+ }
+
+ public LuceneIndexer getIndexer() {
+ return indexer;
+ }
+
+ public void setIndexer(LuceneIndexer indexer) {
+ this.indexer = indexer;
+ }
+
+}
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexProducer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java (added)
+++ camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,163 @@
+/**
+ * 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 java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.converter.IOConverter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.store.NIOFSDirectory;
+
+public class LuceneIndexer {
+ private static final transient Log LOG = LogFactory.getLog(LuceneIndexer.class);
+ private File sourceDirectory;
+ private Analyzer analyzer;
+ private NIOFSDirectory niofsDirectory;
+ private IndexWriter indexWriter;
+ private boolean sourceDirectoryIndexed;
+ private boolean indexCreated;
+
+ public LuceneIndexer(File sourceDirectory, File indexDirectory, Analyzer analyzer) throws Exception {
+ if (indexDirectory != null) {
+ if (!indexDirectory.exists()) {
+ indexDirectory.mkdir();
+ }
+ this.setNiofsDirectory(new NIOFSDirectory(indexDirectory));
+ } else {
+ this.setNiofsDirectory(new NIOFSDirectory(new File("./indexDirectory")));
+ }
+
+ this.setAnalyzer(analyzer);
+
+ if ((sourceDirectory != null) && (!sourceDirectoryIndexed)) {
+ this.setSourceDirectory(sourceDirectory);
+ add(getSourceDirectory());
+ sourceDirectoryIndexed = true;
+ }
+ }
+
+ public void index(Exchange exchange) throws Exception {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Indexing " + exchange);
+ }
+ openIndexWriter();
+ Map<String, Object> headers = exchange.getIn().getHeaders();
+ add("exchangeId", exchange.getExchangeId(), true);
+ Iterator<String> iterator = headers.keySet().iterator();
+ while (iterator.hasNext()) {
+ String field = iterator.next();
+ String value = (String) headers.get(field);
+ add(field, value, true);
+ }
+ add("contents", exchange.getIn().getMandatoryBody(String.class), true);
+ closeIndexWriter();
+ }
+
+ public NIOFSDirectory getNiofsDirectory() {
+ return niofsDirectory;
+ }
+
+ public void setNiofsDirectory(NIOFSDirectory niofsDirectory) {
+ this.niofsDirectory = niofsDirectory;
+ }
+
+ public File getSourceDirectory() {
+ return sourceDirectory;
+ }
+
+ public void setSourceDirectory(File sourceDirectory) {
+ this.sourceDirectory = sourceDirectory;
+ }
+
+ public Analyzer getAnalyzer() {
+ return analyzer;
+ }
+
+ public void setAnalyzer(Analyzer analyzer) {
+ this.analyzer = analyzer;
+ }
+
+ private void add(String field, String value, boolean analyzed) throws IOException {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Adding field: " + field);
+ LOG.trace(" value: " + value);
+ }
+
+ Document doc = new Document();
+ if (!analyzed) {
+ doc.add(new Field(field, value, Field.Store.YES, Field.Index.NOT_ANALYZED));
+ } else {
+ doc.add(new Field(field, value, Field.Store.YES, Field.Index.ANALYZED));
+ }
+ indexWriter.addDocument(doc);
+ }
+
+ private void add(File file) throws IOException {
+ if (file.canRead()) {
+ if (file.isDirectory()) {
+ String[] files = file.list();
+
+ if (files != null) {
+ for (int i = 0; i < files.length; i++) {
+ add(new File(file.getAbsolutePath() + "/" + files[i]));
+ }
+ }
+ } else {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Adding " + file);
+ }
+
+ openIndexWriter();
+ add("path", file.getPath(), false);
+ add("contents", new String(IOConverter.toByteArray(file)), true);
+ closeIndexWriter();
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Added " + file + " successfully");
+ }
+ }
+ } else {
+ LOG.warn("Directory/File " + file.getAbsolutePath() + "could not be read."
+ + " This directory will not be indexed. Please check permissions and rebuild indexes.");
+ }
+ }
+
+ private void openIndexWriter() throws IOException {
+ if (!indexCreated) {
+ indexWriter = new IndexWriter(niofsDirectory, getAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
+ indexCreated = true;
+ return;
+ }
+ indexWriter = new IndexWriter(niofsDirectory, getAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);
+ }
+
+ private void closeIndexWriter() throws IOException {
+ indexWriter.optimize();
+ indexWriter.commit();
+ indexWriter.close();
+ }
+
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneIndexer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java (added)
+++ camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,74 @@
+/**
+ * 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 java.io.File;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.processor.lucene.support.Hits;
+import org.apache.lucene.analysis.Analyzer;
+
+public class LuceneQueryProducer extends DefaultProducer {
+ LuceneConfiguration config;
+ LuceneSearcher searcher;
+ Analyzer analyzer;
+ File indexDirectory;
+ int maxNumberOfHits;
+
+ public LuceneQueryProducer(Endpoint endpoint, LuceneConfiguration config) throws Exception {
+ super(endpoint);
+ this.config = config;
+ indexDirectory = config.getIndexDirectory();
+ analyzer = config.getAnalyzer();
+ maxNumberOfHits = config.getMaxHits();
+ }
+
+ public void start() throws Exception {
+ searcher = new LuceneSearcher();
+ super.doStart();
+ }
+
+ public void stop() throws Exception {
+ searcher.close();
+ super.doStop();
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ Hits hits;
+
+ String phrase = exchange.getIn().getHeader("QUERY", String.class);
+ if (phrase != null) {
+ searcher.open(indexDirectory, analyzer);
+ hits = searcher.search(phrase, maxNumberOfHits);
+ } else {
+ throw new IllegalArgumentException("SearchPhrase for LucenePhraseQuerySearcher not set. Set the Header value: QUERY");
+ }
+
+ exchange.getIn().setBody(hits);
+ }
+
+ public LuceneConfiguration getConfig() {
+ return config;
+ }
+
+ public void setConfig(LuceneConfiguration config) {
+ this.config = config;
+ }
+
+}
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneQueryProducer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java (added)
+++ camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,90 @@
+/**
+ * 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 java.io.File;
+import java.io.IOException;
+
+import org.apache.camel.processor.lucene.support.Hit;
+import org.apache.camel.processor.lucene.support.Hits;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.IndexSearcher;
+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;
+
+public class LuceneSearcher {
+ private static final transient Log LOG = LogFactory.getLog(LuceneSearcher.class);
+ private Analyzer analyzer;
+ private IndexSearcher indexSearcher;
+ private ScoreDoc[] hits;
+
+ public void open(File indexDirectory, Analyzer analyzer) throws IOException {
+ if (indexDirectory != null) {
+ indexSearcher = new IndexSearcher(new NIOFSDirectory(indexDirectory), true);
+ } else {
+ indexSearcher = new IndexSearcher(new NIOFSDirectory(new File("./indexDirectory")), true);
+ }
+ this.analyzer = analyzer;
+ }
+
+ public void close() throws IOException {
+ indexSearcher.close();
+ }
+
+ public Hits search(String searchPhrase, int maxNumberOfHits) throws Exception {
+ Hits searchHits = new Hits();
+
+ int numberOfHits = doSearch(searchPhrase, maxNumberOfHits);
+ searchHits.setNumberOfHits(numberOfHits);
+
+ for (ScoreDoc hit : hits) {
+ Document selectedDocument = indexSearcher.doc(hit.doc);
+ Hit aHit = new Hit();
+ aHit.setHitLocation(hit.doc);
+ aHit.setScore(hit.score);
+ aHit.setData(selectedDocument.get("contents"));
+ searchHits.getHit().add(aHit);
+ }
+
+ return searchHits;
+ }
+
+ private int doSearch(String searchPhrase, int maxNumberOfHits) throws NullPointerException, ParseException, IOException {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("*** Search Phrase: " + searchPhrase + " ***");
+ }
+
+ QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, "contents", analyzer);
+ Query query = parser.parse(searchPhrase);
+ TopScoreDocCollector collector = TopScoreDocCollector.create(maxNumberOfHits, true);
+ indexSearcher.search(query, collector);
+ hits = collector.topDocs().scoreDocs;
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("*** Search generated " + hits.length + " hits ***");
+ }
+ return hits.length;
+ }
+}
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneSearcher.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java (added)
+++ camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,98 @@
+/**
+ * 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.processor.lucene;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.lucene.LuceneSearcher;
+import org.apache.camel.processor.lucene.support.Hits;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.search.IndexSearcher;
+
+public class LuceneQueryProcessor implements Processor {
+ private File indexDirectory;
+ private Analyzer analyzer;
+ private IndexSearcher indexSearcher;
+ private LuceneSearcher searcher;
+ private String searchPhrase;
+ private int maxNumberOfHits;
+
+ public LuceneQueryProcessor(String indexDirectoryPath, Analyzer analyzer, String defaultSearchPhrase, int maxNumberOfHits) {
+ this.setAnalyzer(analyzer);
+ this.setIndexDirectory(new File(indexDirectoryPath));
+ this.setSearchPhrase(defaultSearchPhrase);
+ this.setMaxNumberOfHits(maxNumberOfHits);
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ Hits hits;
+
+ String phrase = exchange.getIn().getHeader("QUERY", String.class);
+ if (phrase != null) {
+ searcher = new LuceneSearcher();
+ searcher.open(indexDirectory, analyzer);
+ hits = searcher.search(phrase, maxNumberOfHits);
+ } else {
+ throw new IllegalArgumentException("SearchPhrase for LuceneQueryProcessor not set. Set the Header value: QUERY");
+ }
+
+ exchange.getIn().setBody(hits);
+ }
+
+ public Analyzer getAnalyzer() {
+ return analyzer;
+ }
+
+ public void setAnalyzer(Analyzer analyzer) {
+ this.analyzer = analyzer;
+ }
+
+ public IndexSearcher getIndexSearcher() {
+ return indexSearcher;
+ }
+
+ public void setIndexSearcher(IndexSearcher indexSearcher) {
+ this.indexSearcher = indexSearcher;
+ }
+
+ public File getIndexDirectory() {
+ return indexDirectory;
+ }
+
+ public void setIndexDirectory(File indexDirectory) {
+ this.indexDirectory = indexDirectory;
+ }
+
+ public String getSearchPhrase() {
+ return searchPhrase;
+ }
+
+ public void setSearchPhrase(String searchPhrase) {
+ this.searchPhrase = searchPhrase;
+ }
+
+ public int getMaxNumberOfHits() {
+ return maxNumberOfHits;
+ }
+
+ public void setMaxNumberOfHits(int maxNumberOfHits) {
+ this.maxNumberOfHits = maxNumberOfHits;
+ }
+
+}
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/LuceneQueryProcessor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hit.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hit.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hit.java (added)
+++ camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hit.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,54 @@
+/**
+ * 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.processor.lucene.support;
+
+import java.io.Serializable;
+
+public class Hit implements Serializable {
+ private int hitLocation;
+ private float score;
+ private String data;
+
+ public int getHitLocation() {
+ return hitLocation;
+ }
+
+ public void setHitLocation(int value) {
+ this.hitLocation = value;
+ }
+
+ public float getScore() {
+ return score;
+ }
+
+ public void setScore(float value) {
+ this.score = value;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String value) {
+ this.data = value;
+ }
+
+ @Override
+ public String toString() {
+ return "Hit[location=" + hitLocation + ", score=" + score + ", data=" + data + "]";
+ }
+}
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hit.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hit.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hits.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hits.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hits.java (added)
+++ camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hits.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,48 @@
+/**
+ * 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.processor.lucene.support;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Hits implements Serializable {
+
+ private int numberOfHits;
+ private List<Hit> hit;
+
+ public int getNumberOfHits() {
+ return numberOfHits;
+ }
+
+ public void setNumberOfHits(int value) {
+ this.numberOfHits = value;
+ }
+
+ public List<Hit> getHit() {
+ if (hit == null) {
+ hit = new ArrayList<Hit>();
+ }
+ return hit;
+ }
+
+ @Override
+ public String toString() {
+ return "Hits[numberOfHits=" + numberOfHits + "]";
+ }
+
+}
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hits.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/java/org/apache/camel/processor/lucene/support/Hits.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/main/resources/META-INF/LICENSE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/resources/META-INF/LICENSE.txt?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/resources/META-INF/LICENSE.txt (added)
+++ camel/trunk/components/camel-lucene/src/main/resources/META-INF/LICENSE.txt Tue Jan 5 07:19:41 2010
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
Propchange: camel/trunk/components/camel-lucene/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-lucene/src/main/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/resources/META-INF/NOTICE.txt?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/resources/META-INF/NOTICE.txt (added)
+++ camel/trunk/components/camel-lucene/src/main/resources/META-INF/NOTICE.txt Tue Jan 5 07:19:41 2010
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
Propchange: camel/trunk/components/camel-lucene/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-lucene/src/main/resources/META-INF/services/org/apache/camel/component/lucene
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/main/resources/META-INF/services/org/apache/camel/component/lucene?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/main/resources/META-INF/services/org/apache/camel/component/lucene (added)
+++ camel/trunk/components/camel-lucene/src/main/resources/META-INF/services/org/apache/camel/component/lucene Tue Jan 5 07:19:41 2010
@@ -0,0 +1,17 @@
+# 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.
+#
+
+class=org.apache.camel.component.lucene.LuceneComponent
Added: camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java (added)
+++ camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,197 @@
+/**
+ * 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 java.io.File;
+
+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.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.processor.lucene.support.Hits;
+import org.apache.camel.test.CamelTestSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.analysis.SimpleAnalyzer;
+import org.apache.lucene.analysis.WhitespaceAnalyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.util.Version;
+import org.junit.Test;
+
+public class LuceneIndexAndQueryProducerTest extends CamelTestSupport {
+ private static final transient Log LOG = LogFactory.getLog(LuceneIndexAndQueryProducerTest.class);
+ private String[] humorousQuotes = {
+ "I think, therefore I am. I think - George Carlin",
+ "I have as much authority as the Pope. I just donÕt have as many people who believe it. - George Carlin",
+ "There`s no present. There`s only the immediate future and the recent past - George Carlin",
+ "Politics doesn't make strange bedfellows - marriage does. - Groucho Marx",
+ "I refuse to join any club that would have me as a member. - Groucho Marx",
+ "I tell ya when I was a kid, all I knew was rejection. My yo-yo, it never came back. - Rodney Dangerfield",
+ "I worked in a pet store and people kept asking how big IÕd get. - Rodney Dangerfield"
+ };
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = new JndiRegistry(createJndiContext());
+ registry.bind("std", new File("target/stdindexDir"));
+ registry.bind("load_dir", new File("src/test/resources/sources"));
+ registry.bind("stdAnalyzer", new StandardAnalyzer(Version.LUCENE_CURRENT));
+ registry.bind("simple", new File("target/simpleindexDir"));
+ registry.bind("simpleAnalyzer", new SimpleAnalyzer());
+ registry.bind("whitespace", new File("target/whitespaceindexDir"));
+ registry.bind("whitespaceAnalyzer", new WhitespaceAnalyzer());
+ return registry;
+ }
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ private void sendRequest(final String quote) throws Exception {
+
+ template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+
+ // Set the property of the charset encoding
+ exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
+ Message in = exchange.getIn();
+ in.setBody(quote, String.class);
+ }
+ });
+ }
+
+ private void sendQuery() throws Exception {
+ template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+
+ // Set the property of the charset encoding
+ exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
+ Message in = exchange.getIn();
+ in.setHeader("QUERY", "");
+ }
+ });
+ }
+
+ @Test
+ public void testLuceneIndexProducer() throws Exception {
+ MockEndpoint mockEndpoint = new MockEndpoint("mock:result");
+
+ context.stop();
+ context.addRoutes(new RouteBuilder() {
+ public void configure() {
+ from("direct:start").
+ to("lucene:stdQuotesIndex:insert?analyzer=#stdAnalyzer&indexDir=#std&srcDir=#load_dir").
+ to("lucene:simpleQuotesIndex:insert?analyzer=#simpleAnalyzer&indexDir=#simple&srcDir=#load_dir").
+ to("lucene:whitespaceQuotesIndex:insert?analyzer=#whitespaceAnalyzer&indexDir=#whitespace&srcDir=#load_dir").
+ to("mock:result");
+
+ }
+ });
+ context.start();
+
+ LOG.debug("------------Beginning LuceneIndexProducer Test---------------");
+ for (String quote : humorousQuotes) {
+ sendRequest(quote);
+ }
+
+ mockEndpoint.assertIsSatisfied();
+ LOG.debug("------------Completed LuceneIndexProducer Test---------------");
+ context.stop();
+ }
+
+ @Test
+ public void testLucenePhraseQueryProducer() throws Exception {
+ MockEndpoint mockSearchEndpoint = new MockEndpoint("mock:searchResult");
+
+ context.stop();
+ context.addRoutes(new RouteBuilder() {
+ public void configure() {
+
+ from("direct:start").
+ setHeader("QUERY", constant("Seinfeld")).
+ to("lucene:searchIndex:query?analyzer=#whitespaceAnalyzer&indexDir=#whitespace&maxHits=20").
+ to("direct:next");
+
+ from("direct:next").process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ Hits hits = exchange.getIn().getBody(Hits.class);
+ printResults(hits);
+ }
+
+ private void printResults(Hits hits) {
+ LOG.debug("Number of hits: " + hits.getNumberOfHits());
+ for (int i = 0; i < hits.getNumberOfHits(); i++) {
+ LOG.debug("Hit " + i + " Index Location:" + hits.getHit().get(i).getHitLocation());
+ LOG.debug("Hit " + i + " Score:" + hits.getHit().get(i).getScore());
+ LOG.debug("Hit " + i + " Data:" + hits.getHit().get(i).getData());
+ }
+ }
+ }).to("mock:searchResult");
+ }
+ });
+ context.start();
+ LOG.debug("------------Beginning LuceneQueryProducer Phrase Test---------------");
+
+ sendQuery();
+ mockSearchEndpoint.assertIsSatisfied();
+ LOG.debug("------------Completed LuceneQueryProducer Phrase Test---------------");
+ context.stop();
+ }
+
+ @Test
+ public void testLuceneWildcardQueryProducer() throws Exception {
+ MockEndpoint mockSearchEndpoint = new MockEndpoint("mock:searchResult");
+
+ context.stop();
+ context.addRoutes(new RouteBuilder() {
+ public void configure() {
+
+ from("direct:start").
+ setHeader("QUERY", constant("Grouc?? Marx")).
+ to("lucene:searchIndex:query?analyzer=#stdAnalyzer&indexDir=#std&maxHits=20").
+ to("direct:next");
+
+ from("direct:next").process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ Hits hits = exchange.getIn().getBody(Hits.class);
+ printResults(hits);
+ }
+
+ private void printResults(Hits hits) {
+ LOG.debug("Number of hits: " + hits.getNumberOfHits());
+ for (int i = 0; i < hits.getNumberOfHits(); i++) {
+ LOG.debug("Hit " + i + " Index Location:" + hits.getHit().get(i).getHitLocation());
+ LOG.debug("Hit " + i + " Score:" + hits.getHit().get(i).getScore());
+ LOG.debug("Hit " + i + " Data:" + hits.getHit().get(i).getData());
+ }
+ }
+ }).to("mock:searchResult");
+ }
+ });
+ context.start();
+ LOG.debug("------------Beginning LuceneQueryProducer Wildcard Test---------------");
+
+ sendQuery();
+ mockSearchEndpoint.assertIsSatisfied();
+ LOG.debug("------------Completed LuceneQueryProducer Wildcard Test---------------");
+ context.stop();
+ }
+}
Propchange: camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/component/lucene/LuceneIndexAndQueryProducerTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorTest.java?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorTest.java (added)
+++ camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorTest.java Tue Jan 5 07:19:41 2010
@@ -0,0 +1,142 @@
+/**
+ * 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.processor.lucene;
+
+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.mock.MockEndpoint;
+import org.apache.camel.processor.lucene.support.Hits;
+import org.apache.camel.test.CamelTestSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.analysis.SimpleAnalyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.util.Version;
+import org.junit.Test;
+
+public class LuceneQueryProcessorTest extends CamelTestSupport {
+ private static final transient Log LOG = LogFactory.getLog(LuceneQueryProcessorTest.class);
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ private void sendRequest() throws Exception {
+ template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+
+ // Set the property of the charset encoding
+ exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
+ Message in = exchange.getIn();
+ in.setHeader("QUERY", "");
+ }
+ });
+ }
+
+ @Test
+ public void testPhraseSearcher() throws Exception {
+ final StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
+ MockEndpoint mockSearchEndpoint = new MockEndpoint("mock:searchResult");
+
+ context.stop();
+ context.addRoutes(new RouteBuilder() {
+ public void configure() {
+
+ try {
+ from("direct:start").
+ setHeader("QUERY", constant("Rodney Dangerfield")).
+ process(new LuceneQueryProcessor("target/stdindexDir", analyzer, null, 20)).
+ to("direct:next");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ from("direct:next").process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ Hits hits = exchange.getIn().getBody(Hits.class);
+ printResults(hits);
+ }
+
+ private void printResults(Hits hits) {
+ LOG.debug("Number of hits: " + hits.getNumberOfHits());
+ for (int i = 0; i < hits.getNumberOfHits(); i++) {
+ LOG.debug("Hit " + i + " Index Location:" + hits.getHit().get(i).getHitLocation());
+ LOG.debug("Hit " + i + " Score:" + hits.getHit().get(i).getScore());
+ LOG.debug("Hit " + i + " Data:" + hits.getHit().get(i).getData());
+ }
+ }
+ }).to("mock:searchResult");
+ }
+ });
+ context.start();
+ LOG.debug("------------Beginning Phrase + Standard Analyzer Search Test---------------");
+
+ sendRequest();
+ mockSearchEndpoint.assertIsSatisfied();
+ LOG.debug("------------Completed Phrase + Standard Analyzer Search Test---------------");
+ context.stop();
+ }
+
+ @Test
+ public void testWildcardSearcher() throws Exception {
+ final SimpleAnalyzer analyzer = new SimpleAnalyzer();
+ MockEndpoint mockSearchEndpoint = new MockEndpoint("mock:searchResult");
+
+ context.stop();
+ context.addRoutes(new RouteBuilder() {
+ public void configure() {
+
+ try {
+ from("direct:start").
+ setHeader("QUERY", constant("Carl*")).
+ process(new LuceneQueryProcessor("target/simpleindexDir", analyzer, null, 20)).
+ to("direct:next");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ from("direct:next").process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ Hits hits = exchange.getIn().getBody(Hits.class);
+ printResults(hits);
+ }
+
+ private void printResults(Hits hits) {
+ LOG.debug("Number of hits: " + hits.getNumberOfHits());
+ for (int i = 0; i < hits.getNumberOfHits(); i++) {
+ LOG.debug("Hit " + i + " Index Location:" + hits.getHit().get(i).getHitLocation());
+ LOG.debug("Hit " + i + " Score:" + hits.getHit().get(i).getScore());
+ LOG.debug("Hit " + i + " Data:" + hits.getHit().get(i).getData());
+ }
+ }
+ }).to("mock:searchResult");
+ }
+
+ });
+ context.start();
+ LOG.debug("------------Beginning Wildcard + Simple Analyzer Phrase Searcher Test---------------");
+
+ sendRequest();
+ mockSearchEndpoint.assertIsSatisfied();
+ LOG.debug("------------Completed Wildcard + Simple Analyzer Phrase Searcher Test---------------");
+ context.stop();
+ }
+}
Propchange: camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/test/java/org/apache/camel/processor/lucene/LuceneQueryProcessorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-lucene/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/test/resources/log4j.properties?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/test/resources/log4j.properties (added)
+++ camel/trunk/components/camel-lucene/src/test/resources/log4j.properties Tue Jan 5 07:19:41 2010
@@ -0,0 +1,38 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# The logging properties used for eclipse testing, We want to see debug output on the console.
+#
+log4j.rootLogger=INFO, file
+
+# uncomment the following to enable camel debugging
+log4j.logger.org.apache.camel.component.lucene=DEBUG
+#log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.org.apache.commons.net=TRACE
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+#log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-lucene-test.log
\ No newline at end of file
Propchange: camel/trunk/components/camel-lucene/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-lucene/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-lucene/src/test/resources/sources/quote.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-lucene/src/test/resources/sources/quote.txt?rev=895924&view=auto
==============================================================================
--- camel/trunk/components/camel-lucene/src/test/resources/sources/quote.txt (added)
+++ camel/trunk/components/camel-lucene/src/test/resources/sources/quote.txt Tue Jan 5 07:19:41 2010
@@ -0,0 +1 @@
+I was the best man at the wedding. If I'm the best man, why is she marrying him? - Jerry Seinfeld
\ No newline at end of file
Propchange: camel/trunk/components/camel-lucene/src/test/resources/sources/quote.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-lucene/src/test/resources/sources/quote.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/pom.xml?rev=895924&r1=895923&r2=895924&view=diff
==============================================================================
--- camel/trunk/components/pom.xml (original)
+++ camel/trunk/components/pom.xml Tue Jan 5 07:19:41 2010
@@ -66,6 +66,7 @@
<module>camel-juel</module>
<module>camel-jxpath</module>
<module>camel-ldap</module>
+ <module>camel-lucene</module>
<module>camel-mail</module>
<module>camel-mina</module>
<module>camel-msv</module>