use of org.apache.camel.processor.lucene.support.Hits in project camel by apache.
the class LuceneQueryProcessorTest method testPhraseSearcher.
@Test
public void testPhraseSearcher() throws Exception {
final StandardAnalyzer analyzer = new StandardAnalyzer();
MockEndpoint mockSearchEndpoint = getMockEndpoint("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();
}
use of org.apache.camel.processor.lucene.support.Hits in project camel by apache.
the class LuceneQueryProcessorTest method testWildcardSearcher.
@Test
public void testWildcardSearcher() throws Exception {
final WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer();
MockEndpoint mockSearchEndpoint = getMockEndpoint("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();
}
use of org.apache.camel.processor.lucene.support.Hits in project camel by apache.
the class LuceneQueryProducer method process.
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);
boolean isReturnLuceneDocs = (returnLuceneDocs != null && returnLuceneDocs.equalsIgnoreCase("true")) ? true : false;
if (phrase != null) {
searcher.open(indexDirectory, analyzer);
hits = searcher.search(phrase, maxNumberOfHits, config.getLuceneVersion(), isReturnLuceneDocs);
} else {
throw new IllegalArgumentException("SearchPhrase for LucenePhraseQuerySearcher not set. Set the Header value: QUERY");
}
exchange.getIn().setBody(hits);
}
Aggregations