public async Task <IndexInformation> GetIndexInfoAsync() { ResourceResponse <DocumentCollection> collectionInfo = await _documentClient.ReadDocumentCollectionAsync( UriFactory.CreateDocumentCollectionUri(_database, _collection)); var indexingPolicy = collectionInfo.Resource.IndexingPolicy; var indexInfo = new IndexInformation() { Automatic = indexingPolicy.Automatic, IndexingMode = indexingPolicy.IndexingMode.ToString(), IncludedPaths = new List <IndexPath>(), ExcludedPaths = new List <IndexPath>() }; foreach (var includedPath in indexingPolicy.IncludedPaths) { indexInfo.IncludedPaths.Add(FillIndexInformation(includedPath)); } foreach (var excludedPath in indexingPolicy.ExcludedPaths) { indexInfo.ExcludedPaths.Add(new IndexPath() { Path = excludedPath.Path }); } return(indexInfo); }
public void GetIndexInfoAsync_return_pathsinformation() { var indexInfo = new IndexInformation() { Automatic = true, IndexingMode = "lazy", IncludedPaths = new List <IndexPath>() { new IndexPath() { Path = "/path1", Indexes = new List <Index>() { new Index { DataType = "String", Kind = "Range", Precision = -1 } } } } }; var database = new Mock <IDatabase>(); database.Setup(x => x.GetIndexInfoAsync()).Returns(Task.FromResult((indexInfo))); var analyze = new Analyze(database.Object); var result = analyze.GetIndexInfoAsync().GetAwaiter().GetResult(); Assert.Single(result.IncludedPaths); }
public List <MappingValidatorType> Validate(IndexInformation index) { var errors = new List <MappingValidatorType>(); IndexMapping currentMappings = GetCurrentIndexMappings(index); List <(Type, List <IndexableProperty>)> correctMappings = GetCorrectMappings(index); foreach ((Type, List <IndexableProperty>)correctMapping in correctMappings) { var properties = new List <MappingValidatorProperty>(); foreach (IndexableProperty indexableProperty in correctMapping.Item2) { CoreIndexer.GetPropertyMapping(indexableProperty, "no", currentMappings, out MappingConflict mappingConflict); if (mappingConflict != MappingConflict.Found) { IEnumerable <string> errorDescriptions = mappingConflict.AsEnumDescriptions(); properties.Add(new MappingValidatorProperty(indexableProperty.Name, errors: errorDescriptions)); } } if (properties.Any()) { errors.Add(new MappingValidatorType(correctMapping.Item1.Name, properties)); } } return(errors); }
private IndexMapping GetCurrentIndexMappings(IndexInformation indexConfig) { Type type = String.IsNullOrEmpty(indexConfig.Type) || indexConfig.Type == "[default]" ? typeof(IndexItem) : Type.GetType(indexConfig.Type); return(_mapping.GetIndexMapping(type, null, indexConfig.Index)); }
private string ValidateMappings(IndexInformation index) { List <MappingValidatorType> errors = _mappingValidatorService.Validate(index); if (errors.Any()) { return(JsonConvert.SerializeObject(errors, Formatting.Indented)); } return("No mapping errors found"); }
private static bool MatchName(IndexInformation i) { foreach (string indexName in _settings.Indices) { if (i.Index.StartsWith(String.Concat(indexName, "-"), StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }
public void CreateIndex() { CreateIndexRequest request = new CreateIndexRequest(); request.IndexName = "testindex"; IndexInformation response = service.Put(request); Assert.That(response.Name == "testindex"); Console.Out.Write(JsonConvert.SerializeObject(response)); }
public ActionResult Index() { var model = online.UserTB.Find(1); int employeeId = online.EmployeeTB.Where(p => p.UserID == 1).FirstOrDefault().EmployeeID; IndexInformation index = new IndexInformation(); index.Email = model.Email; index.UserName = model.Password; index.PassWord = model.Password; index.RecievedResume = online.ResumeEmployeeTB.Where(p => p.EmployeeID == employeeId).Count(); index.TotallForms = online.FormDetailTB.Where(p => p.EmployeeID == employeeId).Count(); return(View(index)); }
private void CheckCaching(IndexInformation indexInformation, byte[] data) { byte.TryParse(Utility.GetAppSetting(Constant.AppSetting_CacheFetchCount), out byte cacheFetchCount); if (cacheFetchCount > 0 && indexInformation.FetchTimes >= cacheFetchCount) { Utility.ConsoleWriteLine($"StartCaching FetchTimes: {indexInformation.FetchTimes}"); indexInformation.Cache(data); Utility.ConsoleWriteLine($"EndCaching FetchTimes: {indexInformation.FetchTimes}"); } else { indexInformation.IncreaseFetchTimes(); } }
private List <(Type, List <IndexableProperty>)> GetCorrectMappings(IndexInformation index) { Type attributeType; if (index.Index.IndexOf(Constants.CommerceProviderName, StringComparison.OrdinalIgnoreCase) > 0) { attributeType = Type.GetType("EPiServer.Commerce.Catalog.DataAnnotations.CatalogContentTypeAttribute, EPiServer.Business.Commerce"); } else { attributeType = Type.GetType("EPiServer.DataAnnotations.ContentTypeAttribute, EPiServer"); } //handle other indextypes? return(GetTypesWithAttribute(attributeType) .Where(t => !t.IsExcludedType()) .Select(type => (type, CoreIndexer.GetIndexableProperties(type, optIn: false))) .ToList()); }
/// <summary> /// When there is a request for reading an item which hasn't written yet, /// but the item has removed because of an exception /// the thread should not wait /// </summary> /// <param name="indexContent"></param> /// <returns></returns> private async Task <bool> IsRemoved(IndexInformation indexInformation, CancellationToken token) { var tcs = new TaskCompletionSource <bool>(); EventHandler handler = null; indexInformation.RemoveHandler += handler = (sender, e) => { indexInformation.RemoveHandler -= handler; // unsubscribe event tcs.SetResult(true); }; token.Register(() => { if (!tcs.Task.IsCompleted) { indexInformation.RemoveHandler -= handler; // unsubscribe event tcs.SetCanceled(); } }); return(await tcs.Task); }
/// <summary> /// Starts the job /// </summary> /// <returns>A status message that will be logged</returns> public override string Execute() { IndexInformation info = new IndexInformation(); Stopwatch tmr = Stopwatch.StartNew(); IClient client = SearchClient.Instance; //Delete all client.Delete<FindProduct>(x => x.MatchType(typeof(FindProduct))); var findHelper = ServiceLocator.Current.GetInstance<FindHelper>(); var language = LanguageSelector.MasterLanguage(); var localizationService = ServiceLocator.Current.GetInstance<LocalizationService>(); var marketService = ServiceLocator.Current.GetInstance<IMarketService>(); var allMarkets = marketService.GetAllMarkets(); var priceService = ServiceLocator.Current.GetInstance<IPriceService>(); var linksRepository = ServiceLocator.Current.GetInstance<ILinksRepository>(); IEnumerable<ContentReference> contentLinks = contentLoader.GetDescendents(Root); int bulkSize = 100; foreach (CultureInfo availableLocalization in localizationService.AvailableLocalizations) { var market = allMarkets.FirstOrDefault(m => m.DefaultLanguage.Equals(availableLocalization)); if (market == null) { continue; } string language2 = availableLocalization.Name.ToLower(); int allContentsCount = contentLinks.Count(); for (var i = 0; i < allContentsCount; i += bulkSize) { var items = contentLoader.GetItems(contentLinks.Skip(i).Take(bulkSize), new LanguageSelector(availableLocalization.Name)); var items2 = items.OfType<IIndexableContent>().ToList(); foreach (var content in items2) { info.NumberOfProductsFound++; OnStatusChanged(String.Format("Searching product {0}/{1} - {2}", i + 1, allContentsCount, content.Name)); if (content.ShouldIndex()) { info.NumberOfProductsFoundAfterExpiredFilter++; var findProduct = content.GetFindProduct(market); //findHelper.GetProductAndVariants(content as CatalogContentBase, availableLocalization, market); if (findProduct != null) { client.Index(findProduct); info.NumberOfProductsIndexed++; } } //For long running jobs periodically check if stop is signaled and if so stop execution if (_stopSignaled) { tmr.Stop(); info.Duration = tmr.ElapsedMilliseconds; break; } } //For long running jobs periodically check if stop is signaled and if so stop execution if (_stopSignaled) { tmr.Stop(); info.Duration = tmr.ElapsedMilliseconds; break; } } } if (_stopSignaled) { return "Stop of job was called. " + info.ToString(); } tmr.Stop(); info.Duration = tmr.ElapsedMilliseconds; return info.ToString(); }
internal IndexInformation CreateCatalogueIndex(Terradue.ElasticCas.Request.CreateIndexRequest createRequest, bool destroy = false) { if (client.IndexExists(i => i.Index(createRequest.IndexName)).Exists) { if (destroy) { client.DeleteIndex(d => d.Index(createRequest.IndexName)); } else { throw new InvalidOperationException(string.Format("'{0}' index already exists and cannot be overriden without data loss", createRequest.IndexName)); } } var response = client.CreateIndex(c => c.Index(createRequest.IndexName)); IndexInformation indexInformation = new IndexInformation(); var status = client.Status(s => s.Index(createRequest.IndexName)); indexInformation.Name = createRequest.IndexName; indexInformation.Shards = status.Shards; indexInformation.Mappings = new Dictionary <string, ICollection <PropertyNameMarker> >(); // Init mappings for each types declared if (createRequest.TypeNames == null || createRequest.TypeNames.Length == 0) { List <string> typeNames = new List <string>(); foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes(typeof(IOpenSearchableElasticType))) { IOpenSearchableElasticType type = (IOpenSearchableElasticType)node.CreateInstance(); if (type is GenericJsonOpenSearchable) { continue; } IndexNameMarker indexName = new IndexNameMarker(); indexName.Name = createRequest.IndexName; PutMappingRequest putMappingRequest = new PutMappingRequest(indexName, type.Type); ((IPutMappingRequest)putMappingRequest).Mapping = type.GetRootMapping(); client.Map(putMappingRequest); indexInformation.Mappings.Add(type.Identifier, ((IPutMappingRequest)putMappingRequest).Mapping.Properties.Keys); typeNames.Add(type.Type.Name); } createRequest.TypeNames = typeNames.ToArray(); } else { foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes(typeof(IElasticItem))) { IOpenSearchableElasticType type = (IOpenSearchableElasticType)node.CreateInstance(); foreach (string typeName in createRequest.TypeNames) { if (typeName == type.Type.Name) { PutMappingRequest putMappingRequest = new PutMappingRequest(type.Index, type.Type); ((IPutMappingRequest)putMappingRequest).Mapping = type.GetRootMapping(); client.Map(putMappingRequest); indexInformation.Mappings.Add(type.Identifier, ((IPutMappingRequest)putMappingRequest).Mapping.Properties.Keys); } } } } return(indexInformation); }
/// <summary> /// Starts the job /// </summary> /// <returns>A status message that will be logged</returns> public override string Execute() { IndexInformation info = new IndexInformation(); Stopwatch tmr = Stopwatch.StartNew(); IClient client = SearchClient.Instance; //Delete all client.Delete <FindProduct>(x => x.MatchType(typeof(FindProduct))); var language = LanguageSelector.MasterLanguage(); var localizationService = ServiceLocator.Current.GetInstance <LocalizationService>(); var marketService = ServiceLocator.Current.GetInstance <IMarketService>(); var allMarkets = marketService.GetAllMarkets(); var priceService = ServiceLocator.Current.GetInstance <IPriceService>(); var linksRepository = ServiceLocator.Current.GetInstance <ILinksRepository>(); // TODO: Add support for multiple catalogs. This will pick the first one. IEnumerable <ContentReference> contentLinks = contentLoader.GetDescendents(Root); int bulkSize = 100; foreach (CultureInfo availableLocalization in localizationService.AvailableLocalizations) { var market = allMarkets.FirstOrDefault(m => m.DefaultLanguage.Equals(availableLocalization)); if (market == null) { continue; } string language2 = availableLocalization.Name.ToLower(); int allContentsCount = contentLinks.Count(); for (var i = 0; i < allContentsCount; i += bulkSize) { var items = contentLoader.GetItems(contentLinks.Skip(i).Take(bulkSize), new LanguageSelector(availableLocalization.Name)); var items2 = items.OfType <IIndexableContent>().ToList(); foreach (var content in items2) { info.NumberOfProductsFound++; OnStatusChanged(String.Format("Searching product {0}/{1} - {2}", i + 1, allContentsCount, content.Name)); if (content.ShouldIndex()) { info.NumberOfProductsFoundAfterExpiredFilter++; var findProduct = content.GetFindProduct(market); if (findProduct != null) { client.Index(findProduct); info.NumberOfProductsIndexed++; } } //For long running jobs periodically check if stop is signaled and if so stop execution if (_stopSignaled) { tmr.Stop(); info.Duration = tmr.ElapsedMilliseconds; break; } } //For long running jobs periodically check if stop is signaled and if so stop execution if (_stopSignaled) { tmr.Stop(); info.Duration = tmr.ElapsedMilliseconds; break; } } } if (_stopSignaled) { return("Stop of job was called. " + info.ToString()); } tmr.Stop(); info.Duration = tmr.ElapsedMilliseconds; return(info.ToString()); }