use of org.apache.lucene.analysis.standard.StandardAnalyzer in project orientdb by orientechnologies.
the class OLuceneAnalyzerFactoryTest method shouldAssignStandardAnalyzerForIndexingUndefined.
@Test
public void shouldAssignStandardAnalyzerForIndexingUndefined() throws Exception {
OLucenePerFieldAnalyzerWrapper analyzer = (OLucenePerFieldAnalyzerWrapper) analyzerFactory.createAnalyzer(indexDef, INDEX, metadata);
//default analyzer for indexing
assertThat(analyzer.getWrappedAnalyzer("undefined")).isInstanceOf(StandardAnalyzer.class);
//default analyzer for indexing
assertThat(analyzer.getWrappedAnalyzer("name")).isInstanceOf(StandardAnalyzer.class);
StandardAnalyzer name = (StandardAnalyzer) analyzer.getWrappedAnalyzer("name");
assertThat(name.getStopwordSet()).isEmpty();
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project orientdb by orientechnologies.
the class OLuceneAnalyzerFactory method buildAnalyzer.
private Analyzer buildAnalyzer(String analyzerFQN, Collection<String> stopwords) {
try {
final Class classAnalyzer = Class.forName(analyzerFQN);
final Constructor constructor = classAnalyzer.getDeclaredConstructor(CharArraySet.class);
return (Analyzer) constructor.newInstance(new CharArraySet(stopwords, true));
} catch (ClassNotFoundException e) {
throw OException.wrapException(new OIndexException("Analyzer: " + analyzerFQN + " not found"), e);
} catch (NoSuchMethodException e) {
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 OLucenePerFieldAnalyzerWrapperTest method shouldReturnCustomAnalyzerForEachField.
@Test
public void shouldReturnCustomAnalyzerForEachField() throws Exception {
OLucenePerFieldAnalyzerWrapper analyzer = new OLucenePerFieldAnalyzerWrapper(new StandardAnalyzer());
analyzer.add("text_en", new EnglishAnalyzer());
analyzer.add("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 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);
}
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(new StandardAnalyzer()).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 = DirectoryReader.open(idx);
searcher = new IndexSearcher(reader);
}
Aggregations