Пример #1
0
        public IndexResult AddGeneralIndex(GeneralDTO general)
        {
            if (general.GeneralID == null)
            {
                return(new IndexResult());
            }
            if (Exists <EntityDocument>(general.GeneralID.Value, DocumentIndexTypeToken.Entity))
            {
                if (_profile.Initialized)
                {
                    _log.WarnFormat("CANNOT PROCESS '{0}CreatedMessage' FOR ENTITY #{1} - '{2}'. ENTITY HAS ALREADY BEEN ADDED ON PROFILE INITIALIZATION OR ENTITY CREATION !!!", general.EntityTypeName, general.GeneralID.GetValueOrDefault(), general.Name);
                }
                else
                {
                    _log.ErrorFormat("CANNOT PROCESS '{0}CreatedMessage' FOR ENTITY #{1} - '{2}'. ENTITY HAS ALREADY BEEN ADDED !!!", general.EntityTypeName, general.GeneralID.GetValueOrDefault(), general.Name);
                }
                return(new IndexResult());
            }
            IDocumentIndex entityIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.Entity);
            EntityDocument document    = _documentFactory.CreateGeneral(general);
            IndexResult    indexResult = document == null ? new IndexResult() : entityIndex.Index(document, false);

            if (indexResult.DocNumber != -1)
            {
                IDocumentIndex projectContextIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityProject);
                projectContextIndex.Index(indexResult.DocNumber, _documentIdFactory.EncodeProjectId(general.ParentProjectID));
                Maybe <string> maybeEntityTypeName = _entityTypeProvider.GetEntityTypeName(general.EntityTypeID);
                string         entityTypeName      = maybeEntityTypeName.FailIfNothing(() => new ApplicationException("Entity type name was not found {0}".Fmt(general.EntityTypeID)));
                IDocumentIndex entityTypeIndex     = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityType);
                entityTypeIndex.Index(indexResult.DocNumber, entityTypeName);
            }
            _log.Debug(string.Format("Added {0} #{1} - '{2}':{3}", general.EntityTypeName, general.GeneralID.GetValueOrDefault(), general.Name, indexResult.WordsAdded.Any() ? string.Format(" added words - {0};", string.Join(",", indexResult.WordsAdded.Keys)) : " NO WORDS ADDED;"));
            return(indexResult);
        }
        private Maybe <QueryPlan> CreateEntityTypePlan(int?entityTypeId)
        {
            if (entityTypeId == null)
            {
                return(Maybe.Nothing);
            }
            Maybe <string> maybeEntityTypeName = _entityTypeProvider.GetEntityTypeName(entityTypeId);
            string         entityTypeName      = maybeEntityTypeName.GetOrThrow(() => new ApplicationException("Entity type name was not found {0}".Fmt(entityTypeId)));
            var            entityTypeFinders   = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext, DocumentIndexTypeToken.EntityType);

            return(entityTypeFinders.BuildExecutionPlan(new ParsedQuery(words: string.Format("+{0}", entityTypeName.ToLower())), _profile.Initialized));
        }
        private Maybe <Lazy <WAHBitArray> > CreateEntityTypePlan(int?entityTypeId)
        {
            if (entityTypeId == null)
            {
                return(Maybe.Nothing);
            }
            Maybe <string> maybeEntityTypeName = _entityTypeProvider.GetEntityTypeName(entityTypeId);
            string         entityTypeName      = maybeEntityTypeName.FailIfNothing(() => new ApplicationException("Entity type name was not found {0}".Fmt(entityTypeId)));
            var            entityTypeFinders   = _documentIndexProvider.GetOrCreateDocumentIndex(_accountName, DocumentIndexTypeToken.EntityType);

            return(entityTypeFinders.BuildExecutionPlan(String.Format("+{0}", entityTypeName.ToLower()), _profile.Initialized));
        }