Search in sources :

Example 6 with LuceneIndexInfo

use of org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo 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

LuceneIndexInfo (org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo)6 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 Test (org.junit.Test)3 Set (java.util.Set)2 Cache (org.apache.geode.cache.Cache)2 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)2 LuceneServiceImpl (org.apache.geode.cache.lucene.internal.LuceneServiceImpl)2 LuceneIndexDetails (org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 FunctionContext (org.apache.geode.cache.execute.FunctionContext)1 ResultSender (org.apache.geode.cache.execute.ResultSender)1 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)1 LuceneIndexFactory (org.apache.geode.cache.lucene.LuceneIndexFactory)1 LuceneService (org.apache.geode.cache.lucene.LuceneService)1 LuceneIndexCreationProfile (org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile)1 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)1 XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)1