示例#1
0
        private JsonDocument RetrieveDocumentInternal(IndexQueryResult queryResult, HashSet<string> loadedIds, string[] fieldsToFetch)
        {
            if (queryResult.Projection == null)
            {
                // duplicate document, filter it out
                if (loadedIds.Add(queryResult.Key) == false)
                    return null;
                return GetDocumentWithCaching(queryResult.Key);
            }

            if (fieldsToFetch != null)
            {
                foreach (var fieldToFetch in fieldsToFetch)
                {
                    if (queryResult.Projection.Property(fieldToFetch) != null)
                        continue;

                    var doc = GetDocumentWithCaching(queryResult.Key);
                    var token = doc.DataAsJson.SelectToken(fieldToFetch);
                    queryResult.Projection[fieldToFetch] = token;
                }
            }

            return new JsonDocument
            {
                Key = queryResult.Key,
                Projection = queryResult.Projection,
            };
        }
示例#2
0
		private JsonDocument RetrieveDocumentInternal(
			IndexQueryResult queryResult,
			HashSet<string> loadedIds,
			IEnumerable<string> fieldsToFetch, 
			IndexDefinition indexDefinition,
			AggregationOperation aggregationOperation)
		{
			if (queryResult.Projection == null)
			{
				// duplicate document, filter it out
				if (loadedIds.Add(queryResult.Key) == false)
					return null;
				return GetDocumentWithCaching(queryResult.Key);
			}

			if (fieldsToFetch != null)
			{
				if (indexDefinition.IsMapReduce == false)
				{
					bool hasStoredFields = false;
					foreach (var fieldToFetch in fieldsToFetch)
					{
						FieldStorage value;
						if (indexDefinition.Stores.TryGetValue(fieldToFetch, out value) == false &&
							value != FieldStorage.No)
							continue;
						hasStoredFields = true;
					}
					if (hasStoredFields == false)
					{
						// duplicate document, filter it out
						if (loadedIds.Add(queryResult.Key) == false)
							return null;
					}
				}
				if (aggregationOperation != AggregationOperation.None)
				{
					var aggOpr = aggregationOperation & ~AggregationOperation.Dynamic;
					fieldsToFetch = fieldsToFetch.Concat(new[] {aggOpr.ToString()});
				}
				var fieldsToFetchFromDocument = fieldsToFetch.Where(fieldToFetch => queryResult.Projection.Property(fieldToFetch) == null);
				var doc = GetDocumentWithCaching(queryResult.Key);
				if (doc != null)
				{
					var result = doc.DataAsJson.SelectTokenWithRavenSyntax(fieldsToFetchFromDocument.ToArray());
					foreach (var property in result.Properties())
					{
						if(property.Value == null || property.Value.Type == JTokenType.Null)
							continue;
						queryResult.Projection[property.Name] = property.Value;
					}
				}
			}

			return new JsonDocument
			{
				Key = queryResult.Key,
				Projection = queryResult.Projection,
			};
		}
示例#3
0
 public bool ShouldIncludeResultInQuery(IndexQueryResult arg)
 {
     var doc = RetrieveDocumentInternal(arg, loadedIdsForFilter);
     if (doc == null)
         return false;
     doc = ProcessReadVetoes(doc, null, ReadOperation.Query);
     return doc != null;
 }
示例#4
0
        private JsonDocument RetrieveDocumentInternal(IndexQueryResult queryResult, HashSet<string> loadedIds, string[] fieldsToFetch, IndexDefinition indexDefinition)
        {
            if (queryResult.Projection == null)
            {
                // duplicate document, filter it out
                if (loadedIds.Add(queryResult.Key) == false)
                    return null;
                return GetDocumentWithCaching(queryResult.Key);
            }

            if (fieldsToFetch != null)
            {
                if (indexDefinition.IsMapReduce == false)
                {
                    bool hasStoredFields = false;
                    foreach (var fieldToFetch in fieldsToFetch)
                    {
                        FieldStorage value;
                        if (indexDefinition.Stores.TryGetValue(fieldToFetch, out value) == false &&
                            value != FieldStorage.No)
                            continue;
                        hasStoredFields = true;
                    }
                    if (hasStoredFields == false)
                    {
                        // duplicate document, filter it out
                        if (loadedIds.Add(queryResult.Key) == false)
                            return null;
                    }
                }
                foreach (var fieldToFetch in fieldsToFetch)
                {
                    if (queryResult.Projection.Property(fieldToFetch) != null)
                        continue;

                    var doc = GetDocumentWithCaching(queryResult.Key);
                    var token = doc.DataAsJson.SelectToken(fieldToFetch);
                    queryResult.Projection[fieldToFetch] = token;
                }
            }

            return new JsonDocument
            {
                Key = queryResult.Key,
                Projection = queryResult.Projection,
            };
        }
示例#5
0
        private JsonDocument RetrieveDocumentInternal(IndexQueryResult queryResult, HashSet<string> loadedIds)
        {
            if (queryResult.Projection == null)
            {
                    // duplicate document, filter it out
                if (loadedIds.Add(queryResult.Key) == false)
                    return null;
                JsonDocument doc;
                if (cache.TryGetValue(queryResult.Key, out doc))
                    return doc;
                doc = actions.Documents.DocumentByKey(queryResult.Key, null);
                cache[queryResult.Key] = doc;
                return doc;
            }

            return new JsonDocument
            {
                Key = queryResult.Key,
                Projection = queryResult.Projection,
            };
        }
示例#6
0
			private bool ShouldIncludeInResults(IndexQueryResult indexQueryResult)
			{
				if (shouldIncludeInResults(indexQueryResult) == false)
					return false;
				if (documentsAlreadySeenInPreviousPage.Contains(indexQueryResult.Key))
					return false;
				if (fieldsToFetch.IsDistinctQuery && alreadyReturned.Add(indexQueryResult.Projection) == false)
					return false;
				return true;
			}
示例#7
0
			private void AddHighlighterResults(IndexSearcher indexSearcher, ScoreDoc scoreDoc, IndexQueryResult indexQueryResult)
			{
				if (highlighter == null)
					return;

				var highlightings =
					from highlightedField in this.indexQuery.HighlightedFields
					select new
					{
						highlightedField.Field,
						highlightedField.FragmentsField,
						Fragments = highlighter.GetBestFragments(
							fieldQuery,
							indexSearcher.IndexReader,
							scoreDoc.Doc,
							highlightedField.Field,
							highlightedField.FragmentLength,
							highlightedField.FragmentCount)
					}
						into fieldHighlitings
						where fieldHighlitings.Fragments != null &&
							  fieldHighlitings.Fragments.Length > 0
						select fieldHighlitings;

				if (fieldsToFetch.IsProjection || parent.IsMapReduce)
				{
					foreach (var highlighting in highlightings)
					{
						if (!string.IsNullOrEmpty(highlighting.FragmentsField))
						{
							indexQueryResult.Projection[highlighting.FragmentsField] = new RavenJArray(highlighting.Fragments);
						}
					}
				}
				else
				{
					indexQueryResult.Highligtings = highlightings.ToDictionary(x => x.Field, x => x.Fragments);
				}
			}
示例#8
0
        private static JsonDocument RetrieveDocument(DocumentStorageActions actions, IndexQueryResult queryResult,
            HashSet<string> loadedIds)
        {
            if (queryResult.Projection == null)
            {
                if (loadedIds.Add(queryResult.Key))
                    return actions.DocumentByKey(queryResult.Key, null);
                return null;
            }

            return new JsonDocument
            {
                Key = queryResult.Key,
                DataAsJosn = queryResult.Projection,
            };
        }
示例#9
0
			private bool ShouldIncludeInResults(IndexQueryResult indexQueryResult)
			{
				if (shouldIncludeInResults(indexQueryResult) == false)
					return false;
				if (fieldsToFetch.IsDistinctQuery && alreadyReturned.Add(indexQueryResult.Projection) == false)
						return false;
				return true;
			}
示例#10
0
 public JsonDocument RetrieveDocumentForQuery(IndexQueryResult queryResult)
 {
     var doc = RetrieveDocumentInternal(queryResult, loadedIdsForRetrieval);
     return ExecuteReadTriggers(doc, null, ReadOperation.Query);
 }
示例#11
0
 public bool ShouldIncludeResultInQuery(IndexQueryResult arg, IndexDefinition indexDefinition, string[] fieldsToFetch)
 {
     var doc = RetrieveDocumentInternal(arg, loadedIdsForFilter, fieldsToFetch, indexDefinition);
     if (doc == null)
         return false;
     doc = ProcessReadVetoes(doc, null, ReadOperation.Query);
     return doc != null;
 }
示例#12
0
 public JsonDocument RetrieveDocumentForQuery(IndexQueryResult queryResult, IndexDefinition indexDefinition, string[] fieldsToFetch)
 {
     var doc = RetrieveDocumentInternal(queryResult, loadedIdsForRetrieval, fieldsToFetch, indexDefinition);
     return ExecuteReadTriggers(doc, null, ReadOperation.Query);
 }
示例#13
0
		public bool Equals(IndexQueryResult other)
		{
			if (ReferenceEquals(null, other)) return false;
			if (ReferenceEquals(this, other)) return true;
			return Equals(other.Key, Key) && new JTokenEqualityComparer().Equals(other.Projection, Projection);
		}