use of org.apache.lucene.analysis.Analyzer in project geode by apache.
the class LuceneServiceImpl method createIndex.
public void createIndex(String indexName, String regionPath, Map<String, Analyzer> fieldAnalyzers) {
if (fieldAnalyzers == null || fieldAnalyzers.isEmpty()) {
throw new IllegalArgumentException("At least one field must be indexed");
}
Analyzer analyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer(), fieldAnalyzers);
Set<String> fieldsSet = fieldAnalyzers.keySet();
String[] fields = (String[]) fieldsSet.toArray(new String[fieldsSet.size()]);
createIndex(indexName, regionPath, analyzer, fieldAnalyzers, fields);
}
use of org.apache.lucene.analysis.Analyzer in project geode by apache.
the class LuceneIndexCreation method beforeCreate.
@Override
public void beforeCreate(Extensible<Region<?, ?>> source, Cache cache) {
LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
Analyzer analyzer = this.fieldAnalyzers == null ? new StandardAnalyzer() : new PerFieldAnalyzerWrapper(new StandardAnalyzer(), this.fieldAnalyzers);
try {
service.createIndex(getName(), getRegionPath(), analyzer, this.fieldAnalyzers, getFieldNames());
} catch (LuceneIndexExistsException e) {
logger.info(LocalizedStrings.LuceneIndexCreation_IGNORING_DUPLICATE_INDEX_CREATION_0_ON_REGION_1.toLocalizedString(e.getIndexName(), e.getRegionPath()));
}
}
use of org.apache.lucene.analysis.Analyzer in project geode by apache.
the class LuceneIndexXmlGenerator method generate.
@Override
public void generate(CacheXmlGenerator cacheXmlGenerator) throws SAXException {
final ContentHandler handler = cacheXmlGenerator.getContentHandler();
handler.startPrefixMapping(PREFIX, NAMESPACE);
AttributesImpl attr = new AttributesImpl();
// TODO - should the type be xs:string ?
XmlGeneratorUtils.addAttribute(attr, NAME, index.getName());
XmlGeneratorUtils.startElement(handler, PREFIX, INDEX, attr);
for (String field : index.getFieldNames()) {
AttributesImpl fieldAttr = new AttributesImpl();
XmlGeneratorUtils.addAttribute(fieldAttr, NAME, field);
Analyzer analyzer = index.getFieldAnalyzers().get(field);
if (analyzer != null) {
XmlGeneratorUtils.addAttribute(fieldAttr, ANALYZER, analyzer.getClass().getName());
}
XmlGeneratorUtils.emptyElement(handler, PREFIX, FIELD, fieldAttr);
}
XmlGeneratorUtils.endElement(handler, PREFIX, INDEX);
}
use of org.apache.lucene.analysis.Analyzer in project geode by apache.
the class LuceneXmlParser method startField.
private void startField(Attributes atts) {
// Ignore any whitespace noise between fields
if (stack.peek() instanceof StringBuffer) {
stack.pop();
}
if (!(stack.peek() instanceof LuceneIndexCreation)) {
throw new CacheXmlException("lucene <field> elements must occur within lucene <index> elements");
}
LuceneIndexCreation creation = (LuceneIndexCreation) stack.peek();
String name = atts.getValue(NAME);
String className = atts.getValue(ANALYZER);
if (className == null) {
creation.addField(name);
} else {
Analyzer analyzer = createAnalyzer(className);
creation.addFieldAndAnalyzer(name, analyzer);
}
}
use of org.apache.lucene.analysis.Analyzer in project geode by apache.
the class LuceneXmlParser method createAnalyzer.
private Analyzer createAnalyzer(String className) {
Object obj;
try {
Class c = InternalDataSerializer.getCachedClass(className);
obj = c.newInstance();
} catch (Exception ex) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_WHILE_INSTANTIATING_A_0.toLocalizedString(className), ex);
}
if (!(obj instanceof Analyzer)) {
throw new CacheXmlException(LocalizedStrings.LuceneXmlParser_CLASS_0_IS_NOT_AN_INSTANCE_OF_ANALYZER.toLocalizedString(className));
}
return (Analyzer) obj;
}
Aggregations