Ejemplo n.º 1
0
        public DocumentIndexTyped(DocumentIndexType indexType, IPluginContext context, Action shuttedDown, DocumentIndexSetup documentIndexSetup, IActivityLoggerFactory loggerFactory, DocumentIndexOptimizeHintFactory optimizeHintFactory)
        {
            _indexType = indexType;
            _logger    = loggerFactory.Create(new PluginContextSnapshot(context));
            var indexPath = _indexType.GetFileFolder(context.AccountName, documentIndexSetup);

            _hoot               = new Hoot(indexPath, _indexType.FileName, _logger.Debug, _logger.Error, indexType.CreateTokensParser(documentIndexSetup), _logger.IsDebugEnabled);
            _shuttedDown        = shuttedDown;
            _isAlive            = true;
            _documentIndexSetup = documentIndexSetup;
            _optimizeHint       = optimizeHintFactory.Create(documentIndexSetup);
            _isOptimized        = true;
            UpdateLastUsedToken();
        }
Ejemplo n.º 2
0
        private IDocumentIndex CreateDocumentIndex(IPluginContext context, DocumentIndexTypeToken documentIndexTypeToken, int?version = null)
        {
            DocumentIndexType charactersIndexType = null;
            DocumentIndexType digitsIndexType     = null;

            if (_documentIndexMetadata.Contains(documentIndexTypeToken, DocumentIndexDataTypeToken.Characters))
            {
                charactersIndexType = _documentIndexMetadata.GetDocumentIndexType(documentIndexTypeToken, DocumentIndexDataTypeToken.Characters);
            }
            if (_documentIndexMetadata.Contains(documentIndexTypeToken, DocumentIndexDataTypeToken.Digits))
            {
                digitsIndexType = _documentIndexMetadata.GetDocumentIndexType(documentIndexTypeToken, DocumentIndexDataTypeToken.Digits);
            }
            if (version != null)
            {
                if (charactersIndexType != null)
                {
                    charactersIndexType = charactersIndexType.CreateVersion(version.Value);
                }
                if (digitsIndexType != null)
                {
                    digitsIndexType = digitsIndexType.CreateVersion(version.Value);
                }
            }
            DocumentIndexMonitor monitor = null;
            Action detachIndex           = () =>
            {
                if (monitor != null)
                {
                    monitor.DetachIndex();
                }
            };
            IActivityLogger logger = _loggerFactory.Create(new PluginContextSnapshot(context));

            monitor = new DocumentIndexMonitor(charactersIndexType ?? digitsIndexType, () =>
            {
                if (charactersIndexType != null)
                {
                    return(digitsIndexType != null
                                                                   ? (IDocumentIndex) new DocumentIndex(charactersIndexType, digitsIndexType, context, detachIndex, _documentIndexSetup, _loggerFactory, _optimizeHintFactory)
                                                                   : new DocumentIndexTyped(charactersIndexType, context, detachIndex, _documentIndexSetup, _loggerFactory, _optimizeHintFactory));
                }
                throw new ApplicationException("Characters index for {0} type is not supported.".Fmt(documentIndexTypeToken));
            }, logger);
            return(monitor);
        }