本文介绍了如何在Azure Blob上实现快速搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨我完成了编写上传文件(文本文件)到azure blob存储的代码。现在我想提供基于文本文件内容的搜索。对于前者如果我搜索Hello,则包含Hello字样的文件名称应出现在搜索结果中。这里我的搜索代码 class BlobSearch { static void Main( string [] args) { string searchText = Hello ; CloudStorageAccount account = CloudStorageAccount.Parse(azureConString); CloudBlobClient blobClient = account.CreateCloudBlobClient(); CloudBlobContainer blobContainer = blobClient.GetContainerReference( MyBlobContainer); blobContainer.FetchAttributes(); var blobItemList = blobContainer.ListBlobs(); foreach ( var item in blobItemList) { string line = string .Empty ; CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(item.Uri.ToString()); if (blockBlob.Name.Contains( .txt)) { int lineno = 1 ; 使用( var stream = blockBlob.OpenRead()) { 使用(StreamReader reader = new StreamReader(stream)) { while ((line = reader.ReadLine())!= null ) { if (line.IndexOf(searchText)!= -1) { Console.WriteLine( 行: + lineno + => + blockBlob.Name); } lineno ++; } } } } } Console.WriteLine( SEARCH COMPLETE); Console.ReadLine(); } } 以上代码正常运行,但速度太慢。有没有办法更快地完成它或改进上面的代码。 谢谢。解决方案 HiI am done with writing the code to upload files (text files) to azure blob storage. Now I want to provide search based on text files content. For ex. If I search for "Hello" then the name of files that contains "Hello" words should appear in search result. Here my code to searchclass BlobSearch{ static void Main(string[] args) { string searchText = "Hello"; CloudStorageAccount account = CloudStorageAccount.Parse(azureConString); CloudBlobClient blobClient = account.CreateCloudBlobClient(); CloudBlobContainer blobContainer = blobClient.GetContainerReference("MyBlobContainer"); blobContainer.FetchAttributes(); var blobItemList = blobContainer.ListBlobs(); foreach (var item in blobItemList) { string line = string.Empty; CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(item.Uri.ToString()); if(blockBlob.Name.Contains(".txt")) { int lineno = 1; using (var stream = blockBlob.OpenRead()) { using (StreamReader reader = new StreamReader(stream)) { while ((line = reader.ReadLine()) != null) { if (line.IndexOf(searchText) != -1) { Console.WriteLine("Line : " + lineno +" => "+ blockBlob.Name); } lineno++; } } } } } Console.WriteLine("SEARCH COMPLETE"); Console.ReadLine(); }}Above code is working but it is too slow. Is there any way to do it faster or improve above code.Thank You. 解决方案 这篇关于如何在Azure Blob上实现快速搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 01:54