use of org.apache.geode.cache.lucene.LuceneIndexFactory in project geode by apache.
the class LuceneTestUtilities method createIndex.
public static void createIndex(Cache cache, String... fieldNames) {
final LuceneIndexFactory indexFactory = LuceneServiceProvider.get(cache).createIndexFactory();
indexFactory.setFields(fieldNames).create(INDEX_NAME, REGION_NAME);
}
use of org.apache.geode.cache.lucene.LuceneIndexFactory in project geode by apache.
the class LuceneCreateIndexFunction method execute.
public void execute(final FunctionContext context) {
String memberId = null;
try {
final LuceneIndexInfo indexInfo = (LuceneIndexInfo) context.getArguments();
final Cache cache = getCache();
memberId = cache.getDistributedSystem().getDistributedMember().getId();
LuceneService service = LuceneServiceProvider.get(cache);
INDEX_NAME.validateName(indexInfo.getIndexName());
String[] fields = indexInfo.getSearchableFieldNames();
String[] analyzerName = indexInfo.getFieldAnalyzers();
final LuceneIndexFactory indexFactory = service.createIndexFactory();
if (analyzerName == null || analyzerName.length == 0) {
for (String field : fields) {
indexFactory.addField(field);
}
} else {
if (analyzerName.length != fields.length)
throw new Exception("Mismatch in lengths of fields and analyzers");
for (int i = 0; i < fields.length; i++) {
Analyzer analyzer = toAnalyzer(analyzerName[i]);
indexFactory.addField(fields[i], analyzer);
}
}
REGION_PATH.validateName(indexInfo.getRegionPath());
indexFactory.create(indexInfo.getIndexName(), indexInfo.getRegionPath());
// TODO - update cluster configuration by returning a valid XmlEntity
XmlEntity xmlEntity = null;
context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity));
} catch (Exception e) {
String exceptionMessage = CliStrings.format(CliStrings.EXCEPTION_CLASS_AND_MESSAGE, e.getClass().getName(), e.getMessage());
context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage()));
}
}
Aggregations