本文整理汇总了C#中RavenJObject.ToLookup方法的典型用法代码示例。如果您正苦于以下问题:C# RavenJObject.ToLookup方法的具体用法?C# RavenJObject.ToLookup怎么用?C# RavenJObject.ToLookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RavenJObject
的用法示例。
在下文中一共展示了RavenJObject.ToLookup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
private void Index(IndexWriter writer, string key, RavenJObject metadata, Etag etag, bool recreateSearcher)
{
if (filesystem.ReadTriggers.CanReadFile(key, metadata, ReadOperation.Index) == false)
return;
lock (writerLock)
{
var lowerKey = key.ToLowerInvariant();
var doc = CreateDocument(lowerKey, metadata);
// REVIEW: Check if there is more straight-forward/efficient pattern out there to work with RavenJObjects.
var lookup = metadata.ToLookup(x => x.Key);
foreach (var metadataKey in lookup)
{
foreach (var metadataHolder in metadataKey)
{
var array = metadataHolder.Value as RavenJArray;
if (array != null)
{
// Object is an array. Therefore, we index each token.
foreach (var item in array)
AddField(doc, metadataHolder.Key, item.ToString());
}
else
{
AddField(doc, metadataHolder.Key, metadataHolder.Value.ToString());
}
}
}
if (doc.GetField(Constants.MetadataEtagField) == null)
doc.Add(new Field(Constants.MetadataEtagField, etag.ToString(), Field.Store.NO, Field.Index.ANALYZED_NO_NORMS));
writer.DeleteDocuments(new Term("__key", lowerKey));
writer.AddDocument(doc);
var customCommitData = new Dictionary<string, string> { { "LastETag", etag.ToString() } };
writer.Commit(customCommitData);
if (recreateSearcher)
ReplaceSearcher(writer);
}
}
示例2: Index
public virtual void Index(string key, RavenJObject metadata)
{
lock (writerLock)
{
var lowerKey = key.ToLowerInvariant();
var doc = CreateDocument(lowerKey, metadata);
// REVIEW: Check if there is more straight-forward/efficient pattern out there to work with RavenJObjects.
var lookup = metadata.ToLookup(x => x.Key);
foreach ( var metadataKey in lookup )
{
foreach ( var metadataHolder in metadataKey )
{
var array = metadataHolder.Value as RavenJArray;
if (array != null)
{
// Object is an array. Therefore, we index each token.
foreach (var item in array)
doc.Add(new Field(metadataHolder.Key, item.ToString(), Field.Store.NO, Field.Index.ANALYZED_NO_NORMS));
}
else doc.Add(new Field(metadataHolder.Key, metadataHolder.Value.ToString(), Field.Store.NO, Field.Index.ANALYZED_NO_NORMS));
}
}
writer.DeleteDocuments(new Term("__key", lowerKey));
writer.AddDocument(doc);
// yes, this is slow, but we aren't expecting high writes count
writer.Commit();
ReplaceSearcher();
}
}