本文整理汇总了C#中Raven.Database.Indexing.FieldsToFetch类的典型用法代码示例。如果您正苦于以下问题:C# FieldsToFetch类的具体用法?C# FieldsToFetch怎么用?C# FieldsToFetch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldsToFetch类属于Raven.Database.Indexing命名空间,在下文中一共展示了FieldsToFetch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IndexQueryOperation
public IndexQueryOperation(Index parent, IndexQuery indexQuery, Func<IndexQueryResult, bool> shouldIncludeInResults,
FieldsToFetch fieldsToFetch, OrderedPartCollection<AbstractIndexQueryTrigger> indexQueryTriggers)
{
this.parent = parent;
this.indexQuery = indexQuery;
this.shouldIncludeInResults = shouldIncludeInResults;
this.fieldsToFetch = fieldsToFetch;
this.indexQueryTriggers = indexQueryTriggers;
if (fieldsToFetch.IsDistinctQuery)
alreadyReturned = new HashSet<RavenJObject>(new RavenJTokenEqualityComparer());
}
示例2: RetrieveDocument
protected virtual IndexQueryResult RetrieveDocument(Document document, FieldsToFetch fieldsToFetch, ScoreDoc score)
{
return new IndexQueryResult
{
Score = score.Score,
Key = document.Get(Constants.DocumentIdFieldName),
Projection = (fieldsToFetch.IsProjection || fieldsToFetch.FetchAllStoredFields) ? CreateDocumentFromFields(document, fieldsToFetch) : null
};
}
示例3: CreateDocumentFromFields
public static RavenJObject CreateDocumentFromFields(Document document, FieldsToFetch fieldsToFetch)
{
var documentFromFields = new RavenJObject();
var fields = fieldsToFetch.Fields;
if (fieldsToFetch.FetchAllStoredFields)
fields = fields.Concat(document.GetFields().Select(x => x.Name));
var q = fields
.Distinct()
.SelectMany(name => document.GetFields(name) ?? new Field[0])
.Where(x => x != null)
.Where(
x =>
x.Name.EndsWith("_IsArray") == false &&
x.Name.EndsWith("_Range") == false &&
x.Name.EndsWith("_ConvertToJson") == false)
.Select(fld => CreateProperty(fld, document))
.GroupBy(x => x.Key)
.Select(g =>
{
if (g.Count() == 1 && document.GetField(g.Key + "_IsArray") == null)
{
return g.First();
}
var ravenJTokens = g.Select(x => x.Value).ToArray();
return new KeyValuePair<string, RavenJToken>(g.Key, new RavenJArray((IEnumerable)ravenJTokens));
});
foreach (var keyValuePair in q)
{
documentFromFields.Add(keyValuePair.Key, keyValuePair.Value);
}
return documentFromFields;
}
示例4: RetrieveDocument
protected override IndexQueryResult RetrieveDocument(Document document, FieldsToFetch fieldsToFetch, ScoreDoc score)
{
fieldsToFetch.EnsureHasField(Constants.ReduceKeyFieldName);
if (fieldsToFetch.HasExplicitFieldsToFetch)
{
return base.RetrieveDocument(document, fieldsToFetch, score);
}
var field = document.GetField(Constants.ReduceValueFieldName);
if (field == null)
{
fieldsToFetch = fieldsToFetch.CloneWith(document.GetFields().Select(x => x.Name).ToArray());
return base.RetrieveDocument(document, fieldsToFetch, score);
}
return new IndexQueryResult
{
Projection = RavenJObject.Parse(field.StringValue),
Score = score.Score
};
}
示例5: DuplicateDocumentRecorder
public DuplicateDocumentRecorder(Searchable indexSearcher,
Index parent,
HashSet<string> documentsAlreadySeenInPreviousPage,
HashSet<RavenJObject> alreadyReturned,
FieldsToFetch fieldsToFetch,
bool isProjectionOrMapReduce)
{
this.indexSearcher = indexSearcher;
this.parent = parent;
this.isProjectionOrMapReduce = isProjectionOrMapReduce;
this.alreadyReturned = alreadyReturned;
this.fieldsToFetch = fieldsToFetch;
this.documentsAlreadySeenInPreviousPage = documentsAlreadySeenInPreviousPage;
}
示例6: RetrieveDocument
protected virtual IndexQueryResult RetrieveDocument(Document document, FieldsToFetch fieldsToFetch)
{
return new IndexQueryResult
{
Key = document.Get(Constants.DocumentIdFieldName),
Projection = fieldsToFetch.IsProjection ? CreateDocumentFromFields(document, fieldsToFetch) : null
};
}
示例7: RetrieveDocument
protected override IndexQueryResult RetrieveDocument(Document document, FieldsToFetch fieldsToFetch, ScoreDoc score)
{
fieldsToFetch.EnsureHasField(Constants.ReduceKeyFieldName);
if (fieldsToFetch.HasExplicitFieldsToFetch)
{
return base.RetrieveDocument(document, fieldsToFetch, score);
}
var field = document.GetField(Constants.ReduceValueFieldName);
if (field == null)
{
fieldsToFetch = fieldsToFetch.CloneWith(document.GetFields().Select(x => x.Name).ToArray());
return base.RetrieveDocument(document, fieldsToFetch, score);
}
var projection = RavenJObject.Parse(field.StringValue);
if (fieldsToFetch.FetchAllStoredFields)
{
var fields = new HashSet<string>(document.GetFields().Select(x => x.Name));
fields.Remove(Constants.ReduceKeyFieldName);
var documentFromFields = new RavenJObject();
AddFieldsToDocument(document, fields, documentFromFields);
foreach (var kvp in projection)
{
documentFromFields[kvp.Key] = kvp.Value;
}
projection = documentFromFields;
}
return new IndexQueryResult
{
Projection = projection,
Score = score.Score,
ReduceVal = field.StringValue
};
}
示例8: Query
public IEnumerable<IndexQueryResult> Query(
string index,
IndexQuery query,
Func<IndexQueryResult, bool> shouldIncludeInResults,
FieldsToFetch fieldsToFetch,
OrderedPartCollection<AbstractIndexQueryTrigger> indexQueryTriggers)
{
Index value;
if (indexes.TryGetValue(index, out value) == false)
{
log.Debug("Query on non existing index '{0}'", index);
throw new InvalidOperationException("Index '" + index + "' does not exists");
}
var indexQueryOperation = new Index.IndexQueryOperation(value, query, shouldIncludeInResults, fieldsToFetch, indexQueryTriggers);
if (query.Query != null && query.Query.Contains(Constants.IntersectSeperator))
return indexQueryOperation.IntersectionQuery();
return indexQueryOperation.Query();
}
示例9: Query
public IEnumerable<IndexQueryResult> Query(
string index,
IndexQuery query,
Func<IndexQueryResult, bool> shouldIncludeInResults,
FieldsToFetch fieldsToFetch)
{
Index value;
if (indexes.TryGetValue(index, out value) == false)
{
log.DebugFormat("Query on non existing index {0}", index);
throw new InvalidOperationException("Index " + index + " does not exists");
}
return new Index.IndexQueryOperation(value, query, shouldIncludeInResults, fieldsToFetch).Query();
}
示例10: Query
public QueryResultWithIncludes Query(string index, IndexQuery query, Action<QueryHeaderInformation> headerInfo, Action<RavenJObject> onResult)
{
index = IndexDefinitionStorage.FixupIndexName(index);
var highlightings = new Dictionary<string, Dictionary<string, string[]>>();
Func<IndexQueryResult, object> tryRecordHighlighting = queryResult =>
{
if (queryResult.Highligtings != null && queryResult.Key != null)
highlightings.Add(queryResult.Key, queryResult.Highligtings);
return null;
};
var stale = false;
Tuple<DateTime, Etag> indexTimestamp = Tuple.Create(DateTime.MinValue, Etag.Empty);
Etag resultEtag = Etag.Empty;
var nonAuthoritativeInformation = false;
if (string.IsNullOrEmpty(query.ResultsTransformer) == false)
{
query.FieldsToFetch = new[] { Constants.AllFields };
}
var idsToLoad = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
TransactionalStorage.Batch(
actions =>
{
var viewGenerator = IndexDefinitionStorage.GetViewGenerator(index);
if (viewGenerator == null)
throw new IndexDoesNotExistsException("Could not find index named: " + index);
resultEtag = GetIndexEtag(index, null);
stale = actions.Staleness.IsIndexStale(index, query.Cutoff, query.CutoffEtag);
indexTimestamp = actions.Staleness.IndexLastUpdatedAt(index);
var indexFailureInformation = actions.Indexing.GetFailureRate(index);
if (indexFailureInformation.IsInvalidIndex)
{
throw new IndexDisabledException(indexFailureInformation);
}
var docRetriever = new DocumentRetriever(actions, ReadTriggers, query.QueryInputs, idsToLoad);
var indexDefinition = GetIndexDefinition(index);
var fieldsToFetch = new FieldsToFetch(query.FieldsToFetch, query.AggregationOperation,
viewGenerator.ReduceDefinition == null
? Constants.DocumentIdFieldName
: Constants.ReduceKeyFieldName);
Func<IndexQueryResult, bool> shouldIncludeInResults =
result => docRetriever.ShouldIncludeResultInQuery(result, indexDefinition, fieldsToFetch);
var indexQueryResults = IndexStorage.Query(index, query, shouldIncludeInResults, fieldsToFetch, IndexQueryTriggers);
indexQueryResults = new ActiveEnumerable<IndexQueryResult>(indexQueryResults);
var transformerErrors = new List<string>();
var results = GetQueryResults(query, viewGenerator, docRetriever,
from queryResult in indexQueryResults
let doc = docRetriever.RetrieveDocumentForQuery(queryResult, indexDefinition, fieldsToFetch)
where doc != null
let _ = nonAuthoritativeInformation |= (doc.NonAuthoritativeInformation ?? false)
let __ = tryRecordHighlighting(queryResult)
select doc, transformerErrors);
if (headerInfo != null)
{
headerInfo(new QueryHeaderInformation
{
Index = index,
IsStable = stale,
ResultEtag = resultEtag,
IndexTimestamp = indexTimestamp.Item1,
IndexEtag = indexTimestamp.Item2,
TotalResults = query.TotalSize.Value
});
}
using (new CurrentTransformationScope(docRetriever))
{
foreach (var result in results)
{
onResult(result);
}
if (transformerErrors.Count > 0)
{
throw new InvalidOperationException("The transform results function failed.\r\n" + string.Join("\r\n", transformerErrors));
}
}
});
return new QueryResultWithIncludes
{
IndexName = index,
IsStale = stale,
NonAuthoritativeInformation = nonAuthoritativeInformation,
SkippedResults = query.SkippedResults.Value,
TotalResults = query.TotalSize.Value,
IndexTimestamp = indexTimestamp.Item1,
IndexEtag = indexTimestamp.Item2,
ResultEtag = resultEtag,
IdsToInclude = idsToLoad,
LastQueryTime = SystemTime.UtcNow,
Highlightings = highlightings
};
//.........这里部分代码省略.........
示例11: GetLuceneQuery
public Query GetLuceneQuery(string index, IndexQuery query, OrderedPartCollection<AbstractIndexQueryTrigger> indexQueryTriggers)
{
Index value;
if (indexes.TryGetValue(index, out value) == false)
{
log.Debug("Query on non existing index {0}", index);
throw new InvalidOperationException("Index '" + index + "' does not exists");
}
var fieldsToFetch = new FieldsToFetch(new string[0], AggregationOperation.None, null);
return new Index.IndexQueryOperation(value, query, _ => false, fieldsToFetch, indexQueryTriggers).GetLuceneQuery();
}
示例12: Query
public QueryResult Query(string index, IndexQuery query)
{
index = IndexDefinitionStorage.FixupIndexName(index);
var list = new List<RavenJObject>();
var stale = false;
Tuple<DateTime, Guid> indexTimestamp = Tuple.Create(DateTime.MinValue, Guid.Empty);
TransactionalStorage.Batch(
actions =>
{
var viewGenerator = IndexDefinitionStorage.GetViewGenerator(index);
if (viewGenerator == null)
throw new InvalidOperationException("Could not find index named: " + index);
stale = actions.Staleness.IsIndexStale(index, query.Cutoff, query.CutoffEtag);
indexTimestamp = actions.Staleness.IndexLastUpdatedAt(index);
var indexFailureInformation = actions.Indexing.GetFailureRate(index);
if (indexFailureInformation.IsInvalidIndex)
{
throw new IndexDisabledException(indexFailureInformation);
}
var docRetriever = new DocumentRetriever(actions, ReadTriggers);
var indexDefinition = GetIndexDefinition(index);
var fieldsToFetch = new FieldsToFetch(query.FieldsToFetch, query.AggregationOperation,
viewGenerator.ReduceDefinition == null
? Constants.DocumentIdFieldName
: Constants.ReduceKeyFieldName);
var collection = from queryResult in IndexStorage.Query(index, query, result => docRetriever.ShouldIncludeResultInQuery(result, indexDefinition, fieldsToFetch), fieldsToFetch, IndexQueryTriggers)
select docRetriever.RetrieveDocumentForQuery(queryResult, indexDefinition, fieldsToFetch)
into doc
where doc != null
select doc;
var transformerErrors = new List<string>();
IEnumerable<RavenJObject> results;
if (query.SkipTransformResults == false &&
query.PageSize > 0 && // maybe they just want the stats?
viewGenerator.TransformResultsDefinition != null)
{
var dynamicJsonObjects = collection.Select(x => new DynamicJsonObject(x.ToJson())).ToArray();
var robustEnumerator = new RobustEnumerator(dynamicJsonObjects.Length)
{
OnError =
(exception, o) =>
transformerErrors.Add(string.Format("Doc '{0}', Error: {1}", Index.TryGetDocKey(o),
exception.Message))
};
results =
robustEnumerator.RobustEnumeration(
dynamicJsonObjects,
source => viewGenerator.TransformResultsDefinition(docRetriever, source))
.Select(JsonExtensions.ToJObject);
}
else
{
results = collection.Select(x => x.ToJson());
}
if (query.PageSize > 0) // maybe they just want the query stats?
list.AddRange(results);
if (transformerErrors.Count > 0)
{
throw new InvalidOperationException("The transform results function failed.\r\n" + string.Join("\r\n", transformerErrors));
}
});
return new QueryResult
{
IndexName = index,
Results = list,
IsStale = stale,
SkippedResults = query.SkippedResults.Value,
TotalResults = query.TotalSize.Value,
IndexTimestamp = indexTimestamp.Item1,
IndexEtag = indexTimestamp.Item2
};
}
示例13: Query
public QueryResultWithIncludes Query(string index, IndexQuery query)
{
index = IndexDefinitionStorage.FixupIndexName(index);
var list = new List<RavenJObject>();
var highlightings = new Dictionary<string, Dictionary<string, string[]>>();
var stale = false;
Tuple<DateTime, Guid> indexTimestamp = Tuple.Create(DateTime.MinValue, Guid.Empty);
Guid resultEtag = Guid.Empty;
var nonAuthoritativeInformation = false;
var idsToLoad = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
TransactionalStorage.Batch(
actions =>
{
var viewGenerator = IndexDefinitionStorage.GetViewGenerator(index);
if (viewGenerator == null)
throw new IndexDoesNotExistsException("Could not find index named: " + index);
resultEtag = GetIndexEtag(index, null);
stale = actions.Staleness.IsIndexStale(index, query.Cutoff, query.CutoffEtag);
indexTimestamp = actions.Staleness.IndexLastUpdatedAt(index);
var indexFailureInformation = actions.Indexing.GetFailureRate(index);
if (indexFailureInformation.IsInvalidIndex)
{
throw new IndexDisabledException(indexFailureInformation);
}
var docRetriever = new DocumentRetriever(actions, ReadTriggers, idsToLoad);
var indexDefinition = GetIndexDefinition(index);
var fieldsToFetch = new FieldsToFetch(query.FieldsToFetch, query.AggregationOperation,
viewGenerator.ReduceDefinition == null
? Constants.DocumentIdFieldName
: Constants.ReduceKeyFieldName);
Func<IndexQueryResult, bool> shouldIncludeInResults =
result => docRetriever.ShouldIncludeResultInQuery(result, indexDefinition, fieldsToFetch);
var collection =
from queryResult in
IndexStorage.Query(index, query, shouldIncludeInResults, fieldsToFetch, IndexQueryTriggers)
select new
{
Document = docRetriever.RetrieveDocumentForQuery(queryResult, indexDefinition, fieldsToFetch),
Fragments = queryResult.Highligtings
}
into docWithFragments
where docWithFragments.Document != null
let _ = nonAuthoritativeInformation |= (docWithFragments.Document.NonAuthoritativeInformation ?? false)
select docWithFragments;
var transformerErrors = new List<string>();
IEnumerable<RavenJObject> results;
if (query.SkipTransformResults == false &&
query.PageSize > 0 && // maybe they just want the stats?
viewGenerator.TransformResultsDefinition != null)
{
var dynamicJsonObjects = collection.Select(x => new DynamicJsonObject(x.Document.ToJson())).ToArray();
var robustEnumerator = new RobustEnumerator(workContext, dynamicJsonObjects.Length)
{
OnError =
(exception, o) =>
transformerErrors.Add(string.Format("Doc '{0}', Error: {1}", Index.TryGetDocKey(o),
exception.Message))
};
results =
robustEnumerator.RobustEnumeration(
dynamicJsonObjects.Cast<object>().GetEnumerator(),
source => viewGenerator.TransformResultsDefinition(docRetriever, source))
.Select(JsonExtensions.ToJObject);
}
else
{
var resultList = new List<RavenJObject>();
foreach (var docWithFragments in collection)
{
resultList.Add(docWithFragments.Document.ToJson());
if (docWithFragments.Fragments != null && docWithFragments.Document.Key != null)
highlightings.Add(docWithFragments.Document.Key, docWithFragments.Fragments);
}
results = resultList;
}
list.AddRange(results);
if (transformerErrors.Count > 0)
{
throw new InvalidOperationException("The transform results function failed.\r\n" + string.Join("\r\n", transformerErrors));
}
});
return new QueryResultWithIncludes
{
IndexName = index,
Results = list,
IsStale = stale,
NonAuthoritativeInformation = nonAuthoritativeInformation,
SkippedResults = query.SkippedResults.Value,
TotalResults = query.TotalSize.Value,
IndexTimestamp = indexTimestamp.Item1,
IndexEtag = indexTimestamp.Item2,
ResultEtag = resultEtag,
IdsToInclude = idsToLoad,
//.........这里部分代码省略.........
示例14: IndexQueryOperation
public IndexQueryOperation(
Index parent,
IndexQuery indexQuery,
Func<IndexQueryResult, bool> shouldIncludeInResults,
FieldsToFetch fieldsToFetch)
{
this.parent = parent;
this.indexQuery = indexQuery;
this.shouldIncludeInResults = shouldIncludeInResults;
this.fieldsToFetch = fieldsToFetch;
if (fieldsToFetch.IsDistinctQuery)
alreadyReturned = new HashSet<JObject>(new JTokenEqualityComparer());
}
示例15: GetDocumentQuery
public Query GetDocumentQuery(string index, IndexQuery query, OrderedPartCollection<AbstractIndexQueryTrigger> indexQueryTriggers)
{
var value = TryIndexByName(index);
if (value == null)
{
log.Debug("Query on non existing index {0}", index);
throw new InvalidOperationException("Index '" + index + "' does not exists");
}
var fieldsToFetch = new FieldsToFetch(new string[0], false, null);
return new Index.IndexQueryOperation(value, query, _ => false, fieldsToFetch, indexQueryTriggers).GetDocumentQuery();
}