是否可以将文档上传到 Blob 存储并执行以下操作:
- 获取文档内容并添加到索引。
- 从第 1 点的内容中抓取关键短语并添加到索引中。
我希望关键短语可以被搜索。
我有代码可以将文档上传到 blobstorage,效果非常好,但获得此索引的唯一方法(据我所知)是使用 Azure 搜索服务中的“导入数据”,该服务使用预定义字段创建索引 -如下:
当只需要这些字段并且索引每 5 分钟自动更新一次时,这非常有效。但是当我想要自定义索引时就成了问题
然而,我唯一想要的字段如下:
- fileId
- fileText(这是文档的内容)
- blobURL(允许下载文档)
- keyPhrases(将从 fileText 中提取 - 我也有执行此操作的代码)
我遇到的唯一问题是我需要能够检索文档内容(fileText)才能获取关键短语,但据我了解,只有当文档内容已经在索引中时我才能执行此操作访问该内容?
我对 Azure 的了解非常有限,并且很难找到与我想做的事情类似的事情。
我用来将文档上传到我的 blob 存储的代码如下:
public CloudBlockBlob UploadBlob(HttpPostedFileBase file)
{
string searchServiceName = ConfigurationManager.AppSettings["SearchServiceName"];
string blobStorageKey = ConfigurationManager.AppSettings["BlobStorageKey"];
string blobStorageName = ConfigurationManager.AppSettings["BlobStorageName"];
string blobStorageURL = ConfigurationManager.AppSettings["BlobStorageURL"];
string UserID = User.Identity.GetUserId();
string UploadDateTime = DateTime.Now.ToString("yyyyMMddhhmmss").ToString();
try
{
var path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), UserID + "_" + UploadDateTime + "_" + file.FileName);
file.SaveAs(path);
var credentials = new StorageCredentials(searchServiceName, blobStorageKey);
var client = new CloudBlobClient(new Uri(blobStorageURL), credentials);
// Retrieve a reference to a container. (You need to create one using the mangement portal, or call container.CreateIfNotExists())
var container = client.GetContainerReference(blobStorageName);
// Retrieve reference to a blob named "myfile.gif".
var blockBlob = container.GetBlockBlobReference(UserID + "_" + UploadDateTime + "_" + file.FileName);
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(path))
{
blockBlob.UploadFromStream(fileStream);
}
System.IO.File.Delete(path);
return blockBlob;
}
catch (Exception e)
{
var r = e.Message;
return null;
}
}
我希望我没有提供太多信息,但我不知道如何解释我正在寻找的内容。如果我不明白,请告诉我,以便我解决我的问题。
我不是在寻找讲义代码,只是在寻找正确方向的推动力。
我将不胜感激任何帮助。
Thanks!