Search in sources :

Example 1 with LuceneIndexFactory

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);
}
Also used : LuceneIndexFactory(org.apache.geode.cache.lucene.LuceneIndexFactory)

Example 2 with LuceneIndexFactory

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()));
    }
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) LuceneIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) LuceneIndexFactory(org.apache.geode.cache.lucene.LuceneIndexFactory) Cache(org.apache.geode.cache.Cache) LuceneService(org.apache.geode.cache.lucene.LuceneService)

Aggregations

LuceneIndexFactory (org.apache.geode.cache.lucene.LuceneIndexFactory)2 Cache (org.apache.geode.cache.Cache)1 LuceneService (org.apache.geode.cache.lucene.LuceneService)1 LuceneIndexInfo (org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo)1 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)1 XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1