/// <summary>上传成果</summary> public void UploadProduct(IndexSubmissionContext context, SubmissionProduct product) { var file = product.File; try { product.AppData.UploadFileId = context.AppDataService.Upload(product.File, product.CharSet, this.UploadChunkSize); var appDataResult = context.AppDataService.Save(product.AppData); product.IndexData.DataId = appDataResult.DataId; if (product.AppData.GenerateThumbnail && !appDataResult.Thumbnail.IsNullOrEmpty()) { product.IndexData.Thumbnail = appDataResult.Thumbnail; } if (product.AppData.GenerateFulltext && !appDataResult.Fulltext.IsNullOrEmpty()) { product.IndexData.Fulltext = appDataResult.Fulltext; } var indexSaveRequest = new IndexSaveRequest(); indexSaveRequest.Replace = true; indexSaveRequest.Metadatas = new MetadataCollection(); indexSaveRequest.Metadatas.Add(product.IndexData); context.IndexerService.Save(indexSaveRequest); context.View.RefreshProductStatus(product, "提交成功", string.Empty); } catch (Exception ex) { ModuleBootstrapper.Error(this, nameof(UploadProduct), ex); context.FailureValues.Enqueue(product); context.View.RefreshProductStatus(product, "提交失败", ex.GetFullMessage()); } context.NextProgress(); }
/// <summary>生成论坛索引数据</summary> private static void SaveForumIndex(Func <Dictionary <string, string> > handler, bool replace) { s_ForumTopicIndexHandler.Initialize(); var service = GetService <IndexerServiceWrapper>(); var request = new IndexSaveRequest(); request.Replace = replace; request.Metadatas = new MetadataCollection(); var variables = handler(); var indexData = s_ForumTopicIndexHandler.Handle(variables); request.Metadatas.Add(indexData); service.Save(request); }
/// <summary>保存</summary> public async Task <string[]> SaveAsync(IndexSaveRequest request) { await Validate(request.Metadatas, request.Replace); foreach (TIndexType metadata in request.Metadatas) { IResponse esresult = null; if (request.Replace) { esresult = await this.Client.IndexAsync <TIndexType>(metadata, d => UseInsertQuery(d, metadata)); } else { var path = DocumentPath <TIndexType> .Id(metadata.IIId); esresult = await this.Client.UpdateAsync <TIndexType>(path, descriptor => UseUpdateQuery(descriptor, metadata)); } esresult.ThrowIfIsNotValid(); } return(request.Metadatas.Select(e => e.IIId).ToArray()); }
public void IndexInstance(int instanceId) { var instance = kCaseInputService.GetInstanceIndexModel(instanceId); if (instance == null) { return; } //获取实例信息 MetadataCollection collection = new MetadataCollection(); Metadata metadata = new Metadata(); var resourcekey = "勘探知识库\\知识案例\\" + instance.Id; metadata.IIId = resourcekey.ToMD5(); metadata.IndexedDate = DateTime.Now; metadata.Thumbnail = instance.Chart?.ToString(); metadata.Fulltext = instance.Description; metadata.PageId = "21"; metadata.DataId = instance.Id.ToString(); metadata["dsn"] = "勘探知识库"; metadata.ShowType = IndexShowType.Mixing.ToString(); metadata["title"] = instance.Name; metadata["subject"] = null; metadata["abstract"] = instance.Description; metadata["catalogue"] = instance.KCaseCategory; metadata["author"] = instance.Author; metadata["submitter"] = null; metadata["auditor"] = instance.Auditor; metadata["createddate"] = instance.CreateDate; metadata["submitteddate"] = null; metadata["auditteddate"] = null; metadata["status"] = "已审核"; metadata["frequency"] = null; metadata["period"] = null; metadata["basin"] = null; metadata["firstlevel"] = null; metadata["secondlevel"] = null; metadata["trap"] = null; metadata["well"] = null; metadata["swa"] = null; metadata["miningarea"] = null; metadata["cozone"] = null; metadata["project"] = null; metadata["pc"] = instance.KCaseCategory; metadata["pt"] = "知识案例"; metadata["bd"] = "勘探"; metadata["bt"] = "知识案例"; metadata["bp"] = instance.KCaseTheme; metadata["ba"] = null; metadata["bf"] = null; metadata["system"] = "勘探知识库"; metadata["resourcetype"] = "勘探知识库\\知识案例\\" + instance.KCaseCategory; metadata["resourcekey"] = resourcekey; collection.Add(metadata); IndexSaveRequest indexrequest = new IndexSaveRequest() { Replace = true, Metadatas = collection }; var iiids = _indexService.Save(indexrequest); var indexCount = iiids.Count(); }
public async Task <string[]> Save(IndexSaveRequest request) { return(await ServiceImpl.SaveAsync(request)); }
/// <summary>保存</summary> public async Task <string[]> SaveAsyncInternal(HttpClientWrapper client, IndexSaveRequest request) { return(await client.PostObjectAsync <string[]>(GetActionUrl(nameof(Save)), request).ConfigureAwait(false)); }
/// <summary>保存</summary> public async Task <string[]> SaveAsync(IndexSaveRequest request) { var client = InitHttpClient(); return(await SaveAsyncInternal(client, request).ConfigureAwait(false)); }
/// <summary>保存</summary> public string[] Save(IndexSaveRequest request) { var client = InitHttpClient(); return(Task.Run(() => SaveAsyncInternal(client, request)).Result); }
public int IndexTargetBaiKe(string category, int categoryid, string bot, string pageid, string groupname, string robject) { int indexCount = 0; FilterRequest request = new FilterRequest { Query = new { bot = bot }, Fields = new { bo = 1 }, Sort = new { boid = 1 } }; var botData = _bo2Service.GetBOT(bot); if (botData == null) { return(indexCount); } var bos = _bo2Service.FilterBOs(request); if (bos != null && bos.Count > 0) { MetadataCollection collection = new MetadataCollection(); // 获取默认模板 var defaultTemplate = _kManage2Service.GetDefaultTemplate(categoryid); foreach (var bo in bos) { // 获取bo的模板,如果没有,获取默认模板 var template = _kManage2Service.GetInstanceTemplate(bo.BO, bot); if (template == null) { template = defaultTemplate; } if (template == null) { template = category; } // 获取目录字符串 var catalogueStr = _kManage2Service.GetCatalogueStr(template); Metadata metadata = new Metadata(); var resourcekey = "勘探知识库\\" + category + "\\" + bo.BO; metadata.IIId = resourcekey.ToMD5(); metadata.IndexedDate = DateTime.Now; metadata.Thumbnail = null; metadata.Fulltext = catalogueStr; metadata.PageId = pageid; metadata.DataId = bo.BO; metadata["dsn"] = "勘探知识库"; metadata.ShowType = IndexShowType.Mixing.ToString(); metadata["title"] = bo.BO + robject + groupname; metadata["subject"] = null; metadata["abstract"] = null; metadata["catalogue"] = catalogueStr; metadata["author"] = null; metadata["submitter"] = null; metadata["auditor"] = null; metadata["createddate"] = DateTime.Now; metadata["submitteddate"] = null; metadata["auditteddate"] = null; metadata["status"] = "已审核"; metadata["frequency"] = null; metadata["period"] = null; metadata["basin"] = null; metadata["firstlevel"] = null; metadata["secondlevel"] = null; metadata["trap"] = null; metadata["well"] = null; metadata["swa"] = null; metadata["miningarea"] = null; metadata["cozone"] = null; metadata["project"] = null; metadata["pc"] = category; metadata["pt"] = template; metadata["bd"] = "勘探"; metadata["bt"] = groupname; metadata["bp"] = robject; metadata["ba"] = null; metadata["bf"] = null; metadata["system"] = "勘探知识库"; metadata["resourcetype"] = "勘探知识库\\" + category; metadata["resourcekey"] = resourcekey; metadata[botData.Code] = bo.BO; collection.Add(metadata); } IndexSaveRequest indexrequest = new IndexSaveRequest() { Replace = true, Metadatas = collection }; var iiids = _indexService.Save(indexrequest); indexCount = iiids.Count(); } return(indexCount); }
/// <summary> /// 保存索引数据 /// </summary> public bool SaveAppIndex(Dictionary <Metadata, AppDataSaveRequest> indexMetadatas) { //保存App Data var resourceKeys = indexMetadatas.Where(item => item.Value != null).Select(item => item.Value.ResourceKey).ToList(); var existsResourceKeys = new List <string>(); var notExistsDbResourceKeys = new List <string>(); var appDataMatchResult = GetExistsResourceKeys(resourceKeys.Select(item => item as object).ToArray()); if (appDataMatchResult != null && appDataMatchResult.Total > 0) { existsResourceKeys = appDataMatchResult.Values.Select(item => item.ResourceKey).ToList(); } if (existsResourceKeys.Any()) { IndexDataSaveRequest <AppDataSaveRequest> appDataSaveRequests = new IndexDataSaveRequest <AppDataSaveRequest>(); appDataSaveRequests.Values = indexMetadatas.Where(item => item.Value != null && notExistsDbResourceKeys.Contains(item.Value.ResourceKey)).Select(item => item.Value).ToList(); var appDataSaveResult = _appDataService.SaveMany(appDataSaveRequests); } notExistsDbResourceKeys = resourceKeys.Where(item => !existsResourceKeys.Contains(item)).ToList(); if (notExistsDbResourceKeys.Any()) { IndexDataSaveRequest <AppDataSaveRequest> appDataInsertRequests = new IndexDataSaveRequest <AppDataSaveRequest>(); appDataInsertRequests.Values = indexMetadatas.Where(item => item.Value != null && notExistsDbResourceKeys.Contains(item.Value.ResourceKey)).Select(item => item.Value).ToList(); var appDataResult = _appDataService.InsertMany(appDataInsertRequests); // for (int i = 0; i < appDataResult.Length; i++) { var resourceKey = notExistsDbResourceKeys[i]; var kvpIndexMetadata = indexMetadatas.FirstOrDefault(item => item.Value.ResourceKey == resourceKey); if (!string.IsNullOrWhiteSpace(appDataResult[i].DataId)) { kvpIndexMetadata.Key.DataId = appDataResult[i].DataId; } if (!string.IsNullOrWhiteSpace(appDataResult[i].Thumbnail)) { kvpIndexMetadata.Key.Thumbnail = appDataResult[i].Thumbnail; } if (!string.IsNullOrWhiteSpace(appDataResult[i].Fulltext)) { kvpIndexMetadata.Key.Fulltext = appDataResult[i].Fulltext; } } } //保存Es Metadta var iiids = indexMetadatas.Select(item => item.Key.IIId).ToList(); //var existsDbIIIds = new List<string>(); //var notExistsDbIIIds = new List<string>(); //var esMetadataMatchResult = GetExistsIIIds(iiids.Select(item => item as object).ToArray()); //if (esMetadataMatchResult != null && esMetadataMatchResult.Total > 0) //{ // existsDbIIIds = esMetadataMatchResult.Metadatas.Select(item => item.IIId).ToList(); //} //notExistsDbIIIds = iiids.Where(item => !existsDbIIIds.Contains(item)).ToList(); //if (existsDbIIIds.Any()) //{ var saveRequest = new IndexSaveRequest(); // var metadatas = indexMetadatas.Where(item => existsDbIIIds.Contains(item.Key.IIId)).Select(item => item.Key).ToList(); var metadatas = indexMetadatas.Select(item => item.Key).ToList(); saveRequest.Metadatas = new MetadataCollection(metadatas); saveRequest.Replace = true; _indexerService.Save(saveRequest); // } //if (notExistsDbIIIds.Any()) //{ // var request = new IndexInsertRequest(); // var metadatas = indexMetadatas.Where(item => notExistsDbIIIds.Contains(item.Key.IIId)).Select(item => item.Key).ToList(); // request.Metadatas = new MetadataCollection(metadatas); // _indexerService.Insert(request); //} return(true); }
/// <summary>生成按查询更新请求</summary> private IUpdateByQueryRequest UseUpdateQuery(UpdateByQueryDescriptor <TIndexType> updateDescriptor, IndexSaveRequest request) { var resourceKeys = request.Metadatas.Select(e => e.ResourceKey).ToArray(); updateDescriptor .Type(this.IndexType) .Query(queryDescriptor => queryDescriptor .Terms(e => e .Field(f => f[MetadataConsts.ResourceKey]) .Terms(resourceKeys) ) ); return(updateDescriptor); }
/// <summary>保存</summary> public string[] Save(IndexSaveRequest request) { return(Task.Run(() => SaveAsync(request)).Result); }
/// <summary> 创建索引 </summary> public void IndexData(List <StandardModel> list) { MetadataCollection collection = new MetadataCollection(); foreach (var item in list) { Metadata metadata = new Metadata(); var resourcekey = "勘探知识库\\标准规范\\外部链接\\" + item.Id; metadata.IIId = resourcekey.ToMD5(); metadata.IndexedDate = DateTime.Now; metadata.Thumbnail = null; metadata.Fulltext = null; metadata.PageId = "23"; metadata.DataId = item.Url; metadata["dsn"] = "勘探知识库"; metadata.ShowType = IndexShowType.Mixing.ToString(); metadata["title"] = item.Name; metadata["subject"] = null; metadata["abstract"] = item.Name; metadata["catalogue"] = item.Type; metadata["author"] = null; metadata["submitter"] = null; metadata["auditor"] = null; metadata["createddate"] = null; metadata["submitteddate"] = null; metadata["auditteddate"] = null; metadata["status"] = "已审核"; metadata["frequency"] = null; metadata["period"] = null; metadata["basin"] = null; metadata["firstlevel"] = null; metadata["secondlevel"] = null; metadata["trap"] = null; metadata["well"] = null; metadata["swa"] = null; metadata["miningarea"] = null; metadata["cozone"] = null; metadata["project"] = null; metadata["pc"] = item.Type; metadata["pt"] = "标准规范"; metadata["bd"] = "勘探"; metadata["bt"] = "标准规范"; metadata["bp"] = item.Type; metadata["ba"] = null; metadata["bf"] = null; metadata["system"] = "勘探知识库"; metadata["resourcetype"] = "勘探知识库\\标准规范\\外部链接\\" + item.Type; metadata["resourcekey"] = resourcekey; collection.Add(metadata); } if (collection.Count() > 0) { IndexSaveRequest indexrequest = new IndexSaveRequest() { Replace = true, Metadatas = collection }; var iiids = _indexService.Save(indexrequest); var indexCount = iiids.Count(); } }