コード例 #1
0
            private void ApplyFacetValueHit(FacetValue facetValue, Facet value, int docId, ParsedRange parsedRange, IndexReader indexReader)
            {
                facetValue.Hits++;
                if (
                    IndexQuery.IsDistinct == false &&
                    (value.Aggregation == FacetAggregation.Count || value.Aggregation == FacetAggregation.None)
                    )
                {
                    return;
                }
                FacetValueState set;

                if (matches.TryGetValue(facetValue, out set) == false)
                {
                    matches[facetValue] = set = new FacetValueState
                    {
                        Docs  = new HashSet <int>(),
                        Facet = value,
                        Range = parsedRange
                    };
                }
                if (IndexQuery.IsDistinct)
                {
                    if (IndexQuery.FieldsToFetch.Length == 0)
                    {
                        throw new InvalidOperationException("Cannot process distinct facet query without specifying which fields to distinct upon.");
                    }

                    if (set.AlreadySeen == null)
                    {
                        set.AlreadySeen = new HashSet <StringCollectionValue>();
                    }

                    var document = indexReader.Document(docId);
                    var fields   = new List <string>();
                    foreach (var fieldName in IndexQuery.FieldsToFetch)
                    {
                        foreach (var field in document.GetFields(fieldName))
                        {
                            if (field.StringValue == null)
                            {
                                continue;
                            }
                            fields.Add(field.StringValue);
                        }
                    }
                    if (fields.Count == 0)
                    {
                        throw new InvalidOperationException("Cannot apply distinct facet on [" + string.Join(", ", IndexQuery.FieldsToFetch) +
                                                            "], did you forget to store them in the index? ");
                    }

                    if (set.AlreadySeen.Add(new StringCollectionValue(fields)) == false)
                    {
                        facetValue.Hits--;            // already seen, cancel this
                        return;
                    }
                }
                set.Docs.Add(docId);
            }
コード例 #2
0
            private void ApplyFacetValueHit(FacetValue facetValue, Facet value, int docId, ParsedRange parsedRange)
            {
                facetValue.Hits++;
                if (value.Aggregation == FacetAggregation.Count || value.Aggregation == FacetAggregation.None)
                {
                    return;
                }
                FacetValueState set;

                if (matches.TryGetValue(facetValue, out set) == false)
                {
                    matches[facetValue] = set = new FacetValueState
                    {
                        Docs  = new HashSet <int>(),
                        Facet = value,
                        Range = parsedRange
                    };
                }
                set.Docs.Add(docId);
            }
コード例 #3
0
ファイル: FacetedQueryRunner.cs プロジェクト: randacc/ravendb
 private void ApplyFacetValueHit(FacetValue facetValue, Facet value, int docId, ParsedRange parsedRange)
 {
     facetValue.Hits++;
     if (value.Aggregation == FacetAggregation.Count || value.Aggregation == FacetAggregation.None)
     {
         return;
     }
     FacetValueState set;
     if (matches.TryGetValue(facetValue, out set) == false)
     {
         matches[facetValue] = set = new FacetValueState
         {
             Docs = new HashSet<int>(),
             Facet = value,
             Range = parsedRange
         };
     }
     set.Docs.Add(docId);
 }
コード例 #4
0
            private void ApplyFacetValueHit(FacetValue facetValue, Facet value, int docId, ParsedRange parsedRange, IndexReader indexReader)
            {
                facetValue.Hits++;
                if (
					IndexQuery.IsDistinct == false &&
					(value.Aggregation == FacetAggregation.Count || value.Aggregation == FacetAggregation.None)
				   )
                {
                    return;
                }
                FacetValueState set;
                if (matches.TryGetValue(facetValue, out set) == false)
                {
                    matches[facetValue] = set = new FacetValueState
                    {
                        Docs = new HashSet<int>(),
                        Facet = value,
                        Range = parsedRange
                    };
                }
	            if (IndexQuery.IsDistinct)
	            {
					if(IndexQuery.FieldsToFetch.Length == 0)
						throw new InvalidOperationException("Cannot process distinct facet query without specifying which fields to distinct upon.");

		            if (set.AlreadySeen == null)
			            set.AlreadySeen = new HashSet<StringCollectionValue>();

		            var document = indexReader.Document(docId);
		            var fields = new List<string>();
					foreach (var fieldName in IndexQuery.FieldsToFetch)
		            {
						foreach (var field in document.GetFields(fieldName))
						{
							if (field.StringValue == null)
								continue;
				            fields.Add(field.StringValue);
			            }
		            }
		            if (fields.Count == 0)
			            throw new InvalidOperationException("Cannot apply distinct facet on [" + string.Join(", ", IndexQuery.FieldsToFetch) +
							"], did you forget to store them in the index? ");

		            if (set.AlreadySeen.Add(new StringCollectionValue(fields)) == false)
		            {
			            facetValue.Hits--;// already seen, cancel this
			            return;
		            }
	            }
                set.Docs.Add(docId);
            }