use of org.apache.lucene.analysis.standard.StandardAnalyzer in project orientdb by orientechnologies.
the class VertexIndexTest method testSpacesInQuery.
@Test
public void testSpacesInQuery() throws IOException, ParseException {
IndexWriterConfig conf = new IndexWriterConfig(new StandardAnalyzer());
final RAMDirectory directory = new RAMDirectory();
final IndexWriter writer = new IndexWriter(directory, conf);
Document doc = new Document();
doc.add(new TextField("name", "Max Water", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
doc.add(new TextField("name", "Max Waterson", Field.Store.YES));
writer.addDocument(doc);
doc = new Document();
doc.add(new TextField("name", "Cory Watney", Field.Store.YES));
writer.addDocument(doc);
writer.commit();
IndexReader reader = DirectoryReader.open(directory);
IndexSearcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new StandardAnalyzer();
QueryParser queryParser = new QueryParser("name", analyzer);
final Query query = queryParser.parse("name:Max AND name:Wat*");
final TopDocs topDocs = searcher.search(query, 10);
assertThat(topDocs.totalHits).isEqualTo(2);
for (int i = 0; i < topDocs.totalHits; i++) {
final Document found = searcher.doc(topDocs.scoreDocs[i].doc);
assertThat(found.get("name")).startsWith("Max");
}
reader.close();
writer.close();
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project orientdb by orientechnologies.
the class LuceneBooleanIndexTest method testMemoryIndex.
@Test
public void testMemoryIndex() throws ParseException {
// TODO To be used in evaluate Record
MemoryIndex index = new MemoryIndex();
Document doc = new Document();
doc.add(new StringField("text", "my text", Field.Store.YES));
StandardAnalyzer analyzer = new StandardAnalyzer();
for (IndexableField field : doc.getFields()) {
index.addField(field.name(), field.stringValue(), analyzer);
}
QueryParser parser = new QueryParser("text", analyzer);
float score = index.search(parser.parse("+text:my"));
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project camel by apache.
the class LuceneIndexAndQueryProducerTest method createRegistry.
@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());
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;
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer 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.lucene.analysis.standard.StandardAnalyzer in project querydsl by querydsl.
the class LuceneSerializerNotTokenizedTest method before.
@Before
public void before() throws Exception {
serializer = new LuceneSerializer(false, false);
idx = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(idx, config);
writer.addDocument(createDocument(clooney));
writer.addDocument(createDocument(pitt));
Document document = new Document();
for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) {
document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED));
}
writer.addDocument(document);
writer.close();
IndexReader reader = IndexReader.open(idx);
searcher = new IndexSearcher(reader);
}
Aggregations