【发布时间】:2018-03-10 09:29:38
【问题描述】:
我正在尝试找到一种方法,仅将带有与特定数据匹配的元数据的 blob 存储中的项目带回。所有字段都有一个名为“FlightNo”的键。
我真正想要的是一种方法来查找包含与元数据匹配的所有文件(listBlobs),因此向上一层,然后遍历该组数据,并找到更多匹配项,因为每个文件都有 5 项元数据。
这是我迄今为止非常不友好的代码。
foreach (IListBlobItem item in container.ListBlobs(null, false))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
blob.FetchAttributes();
foreach (var metaDataItem in blob.Metadata)
{
dictionary.Add(metaDataItem.Key, metaDataItem.Value);
}
if (dictionary.Where(r=>r.Key == "FlightNo" && r.Value == FlightNo).Any())
{
if (dictionary.Where(r => r.Key == "FlightDate" && r.Value == FlightDate).Any())
{
if (dictionary.Where(r => r.Key == "FromAirport" && r.Value == FromAirport).Any())
{
if (dictionary.Where(r => r.Key == "ToAirport" && r.Value == ToAirport).Any())
{
if (dictionary.Where(r => r.Key == "ToAirport" && r.Value == ToAirport).Any())
{
retList.Add(new BlobStorage()
{
Filename = blob.Name,
BlobType = blob.BlobType.ToString(),
LastModified = (DateTimeOffset)blob.Properties.LastModified,
ContentType = blob.Properties.ContentType,
Length = blob.Properties.Length,
uri = RemoveSecondary(blob.StorageUri.ToString()),
FlightNo = dictionary.Where(r => r.Key == "FlightNo").Select(r => r.Value).SingleOrDefault(),
Fixture = dictionary.Where(r => r.Key == "FixtureNo").Select(r => r.Value).SingleOrDefault(),
FlightDate = dictionary.Where(r => r.Key == "FlightDate").Select(r => r.Value).SingleOrDefault(),
FromAirport = dictionary.Where(r => r.Key == "FromAirport").Select(r => r.Value).SingleOrDefault(),
ToAirport = dictionary.Where(r => r.Key == "ToAirport").Select(r => r.Value).SingleOrDefault()
});
}
}
}
}
}
dictionary.Clear();
}
}
谢谢。斯科特
【问题讨论】:
-
不完全确定您的问题是什么。但是...搜索 blob 元数据不是一种有效的操作,因为没有索引。您可能会考虑使用某种类型的数据库来保存您的元数据,以方便查询。
-
索引 Blob 元数据并使用 Azure 搜索现在使搜索 Blob 元数据成为一项非常高效的操作。
标签: c# azure azure-blob-storage