Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Maven users will need to add the following dependency to their pom.xml for this component:

Code Block
xml
xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-lucene</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

Code Block

lucene:searcherName:insert[?options]
lucene:searcherName:query[?options]

You can append query options to the URI in the following format, ?option=value&option=value&...

Insert Options

Div
classconfluenceTableSmall

Name

Default Value

Description

analyzer

StandardAnalyzer

An Analyzer builds TokenStreams, which analyze text. It thus represents a policy for extracting index terms from text. The value for analyzer can be any class that extends the abstract class

Wiki Markup
{div:class=confluenceTableSmall} || Name || Default Value || Description || | {{analyzer}} | {{StandardAnalyzer}} | An Analyzer builds TokenStreams, which analyze text. It thus represents a policy for extracting index terms from text. The value for analyzer can be any class that extends the abstract class

org.apache.lucene.analysis.Analyzer.

Lucene

also

offers

a

rich

set

of

analyzers

out

of

the

box | | {{indexDir}} | {{

box

indexDir

./indexDirectory

}} |

A

file

system

directory

in

which

index

files

are

created

upon

analysis

of

the

document

by

the

specified

analyzer | | {{srcDir}} | {{null}} | An optional directory containing files to be used to be analyzed and added to the index at producer startup. | {div}

Query Options

analyzer

srcDir

null

An optional directory containing files to be used to be analyzed and added to the index at producer startup.

Query Options

Div
classconfluenceTableSmall

Name

Default Value

Description

analyzer

StandardAnalyzer

An Analyzer builds TokenStreams, which analyze text. It thus represents a policy for extracting index terms from text. The value for analyzer can be any class that extends the abstract class

Wiki Markup
{div:class=confluenceTableSmall} || Name || Default Value || Description || | {{analyzer}} | {{StandardAnalyzer}} | An Analyzer builds TokenStreams, which analyze text. It thus represents a policy for extracting index terms from text. The value for analyzer can be any class that extends the abstract class

org.apache.lucene.analysis.Analyzer.

Lucene

also

offers

a

rich

set

of

analyzers

out

of

the

box | | {{indexDir}} | {{

box

indexDir

./indexDirectory

}} |

A

file

system

directory

in

which

index

files

are

created

upon

analysis

of

the

document

by

the

specified

analyzer | | {{maxHits}} | {{10}} | An integer value that limits the result set of the search operation | {div}

analyzer

maxHits

10

An integer value that limits the result set of the search operation

Sending/Receiving Messages to/from the cache

Message Headers

Div
classconfluenceTableSmall

Header

Description

QUERY

The Lucene Query to performed on the index. The query may include wildcards and phrases

RETURN_LUCENE_DOCSCamel 2.15: Set this header to true to include the actual Lucene documentation when returning hit information.
Wiki Markup
{div:class=confluenceTableSmall} || Header || Description || | {{QUERY}} | The Lucene Query to performed on the index. The query may include wildcards and phrases | {div}

Lucene Producers

This component supports 2 producer endpoints.

...

Example 1: Creating a Lucene index

Code Block

RouteBuilder builder = new RouteBuilder() {
    public void configure() {
       from("direct:start").
           to("lucene:whitespaceQuotesIndex:insert?
               analyzer=#whitespaceAnalyzer&indexDir=#whitespace&srcDir=#load_dir").
           to("mock:result");
    }
};

Example 2: Loading properties into the JNDI registry in the Camel Context

Code Block

@Override
protected JndiRegistry createRegistry() throws Exception {
  JndiRegistry registry =
         new JndiRegistry(createJndiContext());
  registry.bind("whitespace", new File("./whitespaceIndexDir"));
  registry.bind("load_dir",
        new File("src/test/resources/sources"));
  registry.bind("whitespaceAnalyzer",
        new WhitespaceAnalyzer());
  return registry;
}
...
CamelContext context = new DefaultCamelContext(createRegistry());

Example 2: Performing searches using a Query Producer

Code Block

RouteBuilder builder = 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");
   }
};

Example 3: Performing searches using a Query Processor

Code Block

RouteBuilder builder = 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");
   }
};