不太清楚你的意思是“应该单独查询标签以便在GUI中显示它们。”但是每个图像的文档都是直接存储每个标签的属性的起点。
E.g.
public class Image
{
public string Id { get; set; }
public string Name { get; set; }
public Dictionary<string, Dictionary<string, object>> LabelProperties { get; set; }
}
然后,您可以填写此如下:
var img1 = new Image
{
Name = "Image1",
LabelProperties = new Dictionary<string, Dictionary<string, object>>
{
{
"Car",
new Dictionary<string, object>
{
{ "Brand", "GM"},
{ "Color", "Blue"},
{ "Engine type", "Big"},
{ "Total doors", 4}
}
},
{
"House",
new Dictionary<string, object>
{
{ "Location", "Downtown"},
{ "Color", "Blue"},
{ "Size", 240}
}
}
}
};
这就结束了在DB看上去很漂亮的结构JSON:
{
"Name": "Image1",
"LabelProperties": {
"Car": {
"Brand": "GM",
"Color": "Blue",
"Engine type": "Big",
"Total doors": 4
},
"House": {
"Location": "Downtown",
"Color": "Blue",
"Size": 240
}
}
}
然后,您可以查询这个使用动态指标。例如。查找包含一个蓝色的房子所有图片:
var blueHouses = session.Query<Image>()
.Customize(x => x.WaitForNonStaleResults())
.Where(x => Equals(x.LabelProperties["House"]["Color"], "Blue"));
Console.WriteLine("--- All Images Containing a House of Color Blue");
foreach (var item in blueHouses)
{
Console.WriteLine("{0} | {1}", item.Id, item.Name);
}
如果你想对自己的索引可能需要标签查询。完整的例子见the gist。
我并不十分清楚你的担忧/问题。您当前正在分别存储带有属性的图像和标签?该图片仅提及一个标签,您担心要“加入”超过30万张图片? – ryan1234 2013-03-11 22:43:53