Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Adds hybrid search query pipeline stage #4794

Merged
merged 15 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ public static TryCatch<AggregateValue> TryCreate(
tryCreateAggregator = AverageAggregator.TryCreate(continuationToken);
break;

case AggregateOperator.Count:
case AggregateOperator.Count:
case AggregateOperator.CountIf:
tryCreateAggregator = CountAggregator.TryCreate(continuationToken);
break;

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.Pipeline.CrossPartition.HybridSearch
{
using System;
using System.Collections.Generic;
using Microsoft.Azure.Cosmos.CosmosElements;

internal sealed class FullTextStatistics
{
private readonly long[] hitCounts;

public long TotalWordCount { get; }

public ReadOnlyMemory<long> HitCounts => this.hitCounts;

public FullTextStatistics(long totalWordCount, long[] hitCounts)
{
this.TotalWordCount = totalWordCount;
this.hitCounts = hitCounts;
}

public FullTextStatistics(CosmosObject cosmosObject)
{
if (cosmosObject == null)
{
throw new System.ArgumentNullException($"{nameof(cosmosObject)} must not be null.");
}

if (!cosmosObject.TryGetValue(FieldNames.TotalWordCount, out CosmosNumber totalWordCount))
{
throw new System.ArgumentException($"{FieldNames.TotalWordCount} must exist and be a number");
}

if (!cosmosObject.TryGetValue(FieldNames.HitCounts, out CosmosArray hitCountsArray))
{
throw new System.ArgumentException($"{FieldNames.HitCounts} must exist and be an array");
}

long[] hitCounts = new long[hitCountsArray.Count];
for (int index = 0; index < hitCountsArray.Count; ++index)
{
if (!(hitCountsArray[index] is CosmosNumber cosmosNumber))
{
throw new System.ArgumentException($"{FieldNames.HitCounts} must be an array of numbers");
}

hitCounts[index] = Number64.ToLong(cosmosNumber.Value);
}

this.TotalWordCount = Number64.ToLong(totalWordCount.Value);
this.hitCounts = hitCounts;
}

private static class FieldNames
{
public const string TotalWordCount = "totalWordCount";

public const string HitCounts = "hitCounts";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.Pipeline.CrossPartition.HybridSearch
{
using System.Collections.Generic;
using Microsoft.Azure.Cosmos.CosmosElements;

internal sealed class GlobalFullTextSearchStatistics
{
public long DocumentCount { get; }

public IReadOnlyList<FullTextStatistics> FullTextStatistics { get; }

public GlobalFullTextSearchStatistics(long documentCount, IReadOnlyList<FullTextStatistics> fullTextStatistics)
{
this.DocumentCount = documentCount;
this.FullTextStatistics = fullTextStatistics ?? throw new System.ArgumentNullException($"{nameof(fullTextStatistics)} must not be null.");
}

public GlobalFullTextSearchStatistics(CosmosElement cosmosElement)
{
if (cosmosElement == null)
{
throw new System.ArgumentNullException($"{nameof(cosmosElement)} must not be null.");
}

if (!(cosmosElement is CosmosObject cosmosObject))
{
throw new System.ArgumentException($"{nameof(cosmosElement)} must be an object.");
}

if (!cosmosObject.TryGetValue(FieldNames.DocumentCount, out CosmosNumber cosmosNumber))
{
throw new System.ArgumentException($"{FieldNames.DocumentCount} must exist and be a number");
}

if (!cosmosObject.TryGetValue(FieldNames.Statistics, out CosmosArray statisticsArray))
{
throw new System.ArgumentException($"{FieldNames.Statistics} must exist and be an array");
}

List<FullTextStatistics> fullTextStatisticsList = new List<FullTextStatistics>(statisticsArray.Count);
foreach (CosmosElement statisticsElement in statisticsArray)
{
if (!(statisticsElement is CosmosObject))
{
throw new System.ArgumentException($"{FieldNames.Statistics} must be an array of objects");
}

FullTextStatistics fullTextStatistics = new FullTextStatistics(statisticsElement as CosmosObject);
fullTextStatisticsList.Add(fullTextStatistics);
}

this.DocumentCount = Number64.ToLong(cosmosNumber.Value);
this.FullTextStatistics = fullTextStatisticsList;
}

private static class FieldNames
{
public const string DocumentCount = "documentCount";

public const string Statistics = "fullTextStatistics";
}
}
}
Loading
Loading