use of org.apache.lucene.analysis.standard.StandardAnalyzer in project orientdb by orientechnologies.
the class OLuceneAnalyzerFactory method buildAnalyzer.
private Analyzer buildAnalyzer(String analyzerFQN) {
try {
final Class classAnalyzer = Class.forName(analyzerFQN);
final Constructor constructor = classAnalyzer.getConstructor();
return (Analyzer) constructor.newInstance();
} catch (ClassNotFoundException e) {
throw OException.wrapException(new OIndexException("Analyzer: " + analyzerFQN + " not found"), e);
} catch (NoSuchMethodException e) {
Class classAnalyzer = null;
try {
classAnalyzer = Class.forName(analyzerFQN);
return (Analyzer) classAnalyzer.newInstance();
} catch (Throwable e1) {
throw OException.wrapException(new OIndexException("Couldn't instantiate analyzer: public constructor not found"), e);
}
} catch (Exception e) {
OLogManager.instance().error(this, "Error on getting analyzer for Lucene index", e);
}
return new StandardAnalyzer();
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project orientdb by orientechnologies.
the class LuceneVsLuceneTest method init.
@Before
public void init() {
InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql");
db.command(new OCommandScript("sql", getScriptFromStream(stream))).execute();
OSchema schema = db.getMetadata().getSchema();
OFileUtils.deleteRecursively(getPath().getAbsoluteFile());
try {
Directory dir = getDirectory();
analyzer = new OLucenePerFieldAnalyzerWrapper(new StandardAnalyzer());
analyzer.add("title", new StandardAnalyzer()).add("Song.title", new StandardAnalyzer());
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
indexWriter = new IndexWriter(dir, iwc);
} catch (IOException e) {
e.printStackTrace();
}
db.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project orientdb by orientechnologies.
the class OLucenePerFieldAnalyzerWrapperTest method shouldReturnCustomAnalyzerForEachFieldInitializedByConstructor.
@Test
public void shouldReturnCustomAnalyzerForEachFieldInitializedByConstructor() throws Exception {
OLucenePerFieldAnalyzerWrapper analyzer = new OLucenePerFieldAnalyzerWrapper(new StandardAnalyzer(), new HashMap<String, Analyzer>() {
{
put("text_en", new EnglishAnalyzer());
put("text_it", new ItalianAnalyzer());
}
});
assertThat(analyzer.getWrappedAnalyzer("text_en")).isNotNull();
assertThat(analyzer.getWrappedAnalyzer("text_en")).isInstanceOf(EnglishAnalyzer.class);
assertThat(analyzer.getWrappedAnalyzer("text_it")).isNotNull();
assertThat(analyzer.getWrappedAnalyzer("text_it")).isInstanceOf(ItalianAnalyzer.class);
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project orientdb by orientechnologies.
the class OLucenePerFieldAnalyzerWrapperTest method shouldReturnDefaultAnalyzerForEachField.
@Test
public void shouldReturnDefaultAnalyzerForEachField() throws Exception {
OLucenePerFieldAnalyzerWrapper analyzer = new OLucenePerFieldAnalyzerWrapper(new StandardAnalyzer());
assertThat(analyzer.getWrappedAnalyzer("a_field")).isNotNull();
assertThat(analyzer.getWrappedAnalyzer("a_field")).isInstanceOf(StandardAnalyzer.class);
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project orientdb by orientechnologies.
the class OLuceneIndexWriterFactoryTest method shouldCreateIndexWriterConfiguredWithMetadataValues.
@Test
public void shouldCreateIndexWriterConfiguredWithMetadataValues() throws Exception {
OLuceneIndexWriterFactory fc = new OLuceneIndexWriterFactory();
//sample metadata json
ODocument meta = new ODocument().fromJSON(OIOUtils.readFileAsString(new File("./src/test/resources/index_metadata_new.json")));
IndexWriter writer = fc.createIndexWriter(new RAMDirectory(), meta, new StandardAnalyzer());
LiveIndexWriterConfig config = writer.getConfig();
assertThat(config.getUseCompoundFile()).isFalse();
assertThat(config.getAnalyzer()).isInstanceOf(StandardAnalyzer.class);
assertThat(config.getMaxBufferedDocs()).isEqualTo(-1);
assertThat(config.getRAMPerThreadHardLimitMB()).isEqualTo(1024);
}
Aggregations