Exemplo n.º 1
0
        public void UpdateDataSetNameToIndex <TServiceSettings>(ServiceTypeEnum serviceType)
            where TServiceSettings : BaseServiceSettingsElastic
        {
            var dataSets = dataSetService.GetDataSetIndexAlias();

            foreach (var service in serviceQuery.GetByType((int)serviceType))
            {
                var settings = serviceQuery.GetSettings <TServiceSettings>(service.Id);
                if (settings == null)
                {
                    continue;
                }

                var key = dataSets
                          .Where(d => d.Value.EqualsOrdinalIgnoreCase(settings.DataSetName)) // search for aliases
                          .Select(d => d.Key)
                          .FirstOrDefault();
                if (key == null)
                {
                    continue;
                }

                // if alias is used then replace with index name
                settings.DataSetName = key;
                serviceQuery.IndexSettings <TServiceSettings>(settings);
            }
        }
Exemplo n.º 2
0
        public IActionResult Prepare(string id, [FromBody] ClassifierPrepareSettings classifierPrepareSettings)
        {
            //SERVICE VALIDATION
            var service = serviceQuery.Get(id);

            if (service == null)
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status404NotFound, ServiceResources.InvalidIdNotExistingService));
            }
            if (service.Type != (int)ServiceTypeEnum.Classifier)
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest, string.Format(ServiceResources.InvalidServiceTypeOnly_0_ServicesAreValidForThisRequest, "Classifier")));
            }
            if (service.Status != (int)ServiceStatusEnum.New)
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest, ServiceResources.InvalidStatusOnlyTheServicesWithNewStatusCanBePrepared));
            }

            //DATASET VALIDATION
            if (!GlobalStore.DataSets.IsExist(classifierPrepareSettings.DataSetName))
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest,
                                                         string.Format(ServiceResources.DataSet_0_NotFound, classifierPrepareSettings.DataSetName)));
            }

            var globalStoreDataSet = GlobalStore.DataSets.Get(classifierPrepareSettings.DataSetName);
            var dataSet            = globalStoreDataSet.DataSet;

            //NGRAM COUNT LIST VALIDATION
            var nGramResult = CommonValidators.ValidateNGramList(classifierPrepareSettings.NGramList, dataSet.NGramCount);

            if (nGramResult.IsFailure)
            {
                return(HttpErrorResult(StatusCodes.Status400BadRequest, nGramResult.Error));
            }

            //TAGS VALIDATION
            var tagQuery = queryFactory.GetTagQuery(dataSet.Name);
            List <TagElastic> tags;

            if (classifierPrepareSettings?.TagIdList?.Any() == true)
            {
                tags = tagQuery.Get(classifierPrepareSettings.TagIdList).ToList();
                if (tags.Count < classifierPrepareSettings.TagIdList.Count)
                {
                    var missingTagIds = classifierPrepareSettings.TagIdList.Except(tags.Select(t => t.Id)).ToList();
                    return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest,
                                                             string.Format(ServiceResources.TheFollowingTagIdsNotExistInTheDataSet_0, string.Join(", ", missingTagIds))));
                }
            }
            else
            {
                tags = tagQuery.GetAll().Items.Where(i => i.IsLeaf).ToList();
            }

            //SAVE SETTINGS TO ELASTIC
            var serviceSettings = new ClassifierSettingsElastic {
                DataSetName      = globalStoreDataSet.IndexName,
                ServiceId        = service.Id,
                NGramList        = classifierPrepareSettings.NGramList,
                Tags             = tags,
                CompressSettings = CompressHelper.ToCompressSettingsElastic(classifierPrepareSettings.CompressSettings, classifierPrepareSettings.CompressLevel)
            };

            serviceQuery.IndexSettings(serviceSettings);

            var process = processHandler.Create(
                ProcessTypeEnum.ClassifierPrepare,
                service.Id, classifierPrepareSettings,
                string.Format(ServiceResources.Preparing_0_Service_1, ServiceTypeEnum.Classifier, service.Name));

            service.ProcessIdList.Add(process.Id);
            serviceQuery.Update(service.Id, service);

            processHandler.Start(process, (tokenSource) => classifierHandler.Prepare(process.Id, serviceSettings, tokenSource.Token));

            return(new HttpStatusCodeWithObjectResult(StatusCodes.Status202Accepted, process.ToProcessModel()));
        }
Exemplo n.º 3
0
        public IActionResult Prepare(string id, [FromBody] SearchPrepareSettings searchPrepareSettings)
        {
            //SERVICE VALIDATION
            var service = serviceQuery.Get(id);

            if (service == null)
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status404NotFound, ServiceResources.InvalidIdNotExistingService));
            }
            if (service.Type != (int)ServiceTypeEnum.Search)
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest, string.Format(ServiceResources.InvalidServiceTypeOnly_0_ServicesAreValidForThisRequest, "Search")));
            }
            if (service.Status != (int)ServiceStatusEnum.New)
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest, ServiceResources.InvalidStatusOnlyTheServicesWithNewStatusCanBePrepared));
            }

            //DATASET VALIDATION
            if (!GlobalStore.DataSets.IsExist(searchPrepareSettings.DataSetName))
            {
                return(new HttpStatusCodeWithErrorResult(StatusCodes.Status400BadRequest,
                                                         string.Format(ServiceResources.DataSet_0_NotFound, searchPrepareSettings.DataSetName)));
            }

            var globalStoreDataSet = GlobalStore.DataSets.Get(searchPrepareSettings.DataSetName);
            var dataSet            = globalStoreDataSet.DataSet;

            var serviceSettings = new SearchSettingsWrapperElastic
            {
                DataSetName = globalStoreDataSet.DataSet.Name,
                ServiceId   = service.Id
            };

            // SETUP default values for Activation - here we can calculate more accurate settings for the dataset

            var defaultActivationSettings = new SearchActivateSettings();

            serviceSettings.AutoCompleteSettings = new AutoCompleteSettingsElastic
            {
                Confidence    = 2.0,
                Count         = 3,
                MaximumErrors = 0.5
            };

            serviceSettings.SearchSettings = new SearchSettingsElastic
            {
                Count             = 3,
                CutOffFrequency   = 0.001,
                Filter            = null,
                Fuzziness         = -1,
                ResponseFieldList = dataSet.InterpretedFields.Union(new List <string> {
                    dataSet.IdField, dataSet.TagField
                }).ToList(),
                SearchFieldList   = dataSet.InterpretedFields,
                Type              = (int)SearchTypeEnum.Match,
                Weights           = null,
                Operator          = (int)LogicalOperatorEnum.OR,
                UseDefaultFilter  = true,
                UseDefaultWeights = true,
                Order             = null
            };

            serviceQuery.IndexSettings(serviceSettings);

            var process = processHandler.Create(
                ProcessTypeEnum.SearchPrepare,
                service.Id, searchPrepareSettings,
                string.Format(ServiceResources.Preparing_0_Service_1, ServiceTypeEnum.Search, service.Name));

            service.ProcessIdList.Add(process.Id);
            serviceQuery.Update(service.Id, service);

            processHandler.Start(process, (tokenSource) => searchHandler.Prepare(process.Id, serviceSettings, tokenSource.Token));

            return(new HttpStatusCodeWithObjectResult(StatusCodes.Status202Accepted, process.ToProcessModel()));
        }