是否可以将文档上载到blob存储区并执行以下操作:
我希望关键的词组能够被搜索。
我有一些代码可以将文档上传到工作完美的below存储中,但要获得这个索引(据我所知),唯一的方法是在Azure搜索服务中使用"Import“,该服务使用预定义的字段创建和索引--如下所示:

当只需要这些字段并且索引每5分钟自动更新一次时,这是很好的工作。但是当我想要一个自定义索引时,就成了一个问题。
然而,我唯一想要的字段是:
我唯一的问题是,我需要能够检索文档内容(FileText)才能获得keyPhrases,但据我所知,只有当文档内容已经在索引中供我访问该内容时,我才能这样做?
我对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;
}
}我希望我没有提供太多的信息,但我不知道如何解释我在寻找什么。如果我说不通,请让我知道,这样我就可以解决我的问题了。
我不是在寻找施舍代码,我只是在寻找一个正确的方向。
我很感谢你的帮助。
谢谢!
发布于 2016-12-05 07:54:35
通过Azure搜索、REST API和.NET SDK,可以使用Azure搜索对文档进行索引。根据您的描述,我使用.NET SDK创建了一个演示,并成功地进行了测试。以下是我的详细步骤:


[SerializePropertyNamesAsCamelCase] public class TomTestModel { [Key] [IsFilterable] public string fileId { get; set; } [IsSearchable] public string fileText { get; set; } public string blobURL { get; set; } [IsSearchable] public string keyPhrases { get; set; } }4.创建DataSource
string searchServiceName = ConfigurationManager.AppSettings["SearchServiceName"];
string adminApiKey = ConfigurationManager.AppSettings["SearchServiceAdminApiKey"];
SearchServiceClient serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(adminApiKey));
var dataSource = DataSource.AzureBlobStorage("storage name", "connectstrong", "container name");
//create data source
if (serviceClient.DataSources.Exists(dataSource.Name))
{
serviceClient.DataSources.Delete(dataSource.Name);
}
serviceClient.DataSources.Create(dataSource);var definition = new Index() { Name = "tomcustomindex", Fields = FieldBuilder.BuildForType<TomTestModel>() }; //create Index if (serviceClient.Indexes.Exists(definition.Name)) { serviceClient.Indexes.Delete(definition.Name); } var index = serviceClient.Indexes.Create(definition);


Page.config文件:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Azure.Search" version="3.0.0-rc" targetFramework="net452" />
<package id="Microsoft.Data.Edm" version="5.6.4" targetFramework="net452" />
<package id="Microsoft.Data.OData" version="5.6.4" targetFramework="net452" />
<package id="Microsoft.Data.Services.Client" version="5.6.4" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.4" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.4" targetFramework="net452" />
<package id="Microsoft.Spatial" version="6.15.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
<package id="System.Spatial" version="5.6.4" targetFramework="net452" />
<package id="WindowsAzure.Storage" version="7.2.1" targetFramework="net452" />
</packages>TomTestModel文件:
using System.ComponentModel.DataAnnotations;
using Microsoft.Azure.Search;
using Microsoft.Azure.Search.Models;
namespace TomAzureSearchTest
{
[SerializePropertyNamesAsCamelCase]
public class TomTestModel
{
[Key]
[IsFilterable]
public string fileId { get; set; }
[IsSearchable]
public string fileText { get; set; }
public string blobURL { get; set; }
[IsSearchable]
public string keyPhrases { get; set; }
}
}https://stackoverflow.com/questions/40949845
复制相似问题