Search in sources :

Example 81 with StandardAnalyzer

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();
}
Also used : OIndexException(com.orientechnologies.orient.core.index.OIndexException) Constructor(java.lang.reflect.Constructor) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException)

Example 82 with 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();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OLucenePerFieldAnalyzerWrapper(com.orientechnologies.lucene.analyzer.OLucenePerFieldAnalyzerWrapper) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) IndexWriter(org.apache.lucene.index.IndexWriter) InputStream(java.io.InputStream) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) IOException(java.io.IOException) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 83 with StandardAnalyzer

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);
}
Also used : StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) EnglishAnalyzer(org.apache.lucene.analysis.en.EnglishAnalyzer) EnglishAnalyzer(org.apache.lucene.analysis.en.EnglishAnalyzer) ItalianAnalyzer(org.apache.lucene.analysis.it.ItalianAnalyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) ItalianAnalyzer(org.apache.lucene.analysis.it.ItalianAnalyzer) Test(org.junit.Test)

Example 84 with StandardAnalyzer

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);
}
Also used : StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Test(org.junit.Test)

Example 85 with StandardAnalyzer

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);
}
Also used : LiveIndexWriterConfig(org.apache.lucene.index.LiveIndexWriterConfig) IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) File(java.io.File) RAMDirectory(org.apache.lucene.store.RAMDirectory) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)112 Analyzer (org.apache.lucene.analysis.Analyzer)37 IndexWriter (org.apache.lucene.index.IndexWriter)36 Document (org.apache.lucene.document.Document)29 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)29 IndexSearcher (org.apache.lucene.search.IndexSearcher)24 Term (org.apache.lucene.index.Term)22 RAMDirectory (org.apache.lucene.store.RAMDirectory)21 Test (org.junit.Test)21 Query (org.apache.lucene.search.Query)20 BooleanQuery (org.apache.lucene.search.BooleanQuery)19 TermQuery (org.apache.lucene.search.TermQuery)19 IOException (java.io.IOException)16 Before (org.junit.Before)15 IndexReader (org.apache.lucene.index.IndexReader)14 HashMap (java.util.HashMap)13 Field (org.apache.lucene.document.Field)13 ArrayList (java.util.ArrayList)12 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)12 Directory (org.apache.lucene.store.Directory)12