Skip to content

Commit

Permalink
Adding facet selector for collections
Browse files Browse the repository at this point in the history
Adding facets selector based on how the facets are setup.  Allows facets to be selected based on type
query.Facet(x=>x.Categories, c=>c.GuidValue)
  • Loading branch information
JoshuaFolkerts authored Mar 17, 2024
1 parent 338d007 commit 47dd57f
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions APIs/src/EpiServer.ContentGraph/Api/Querying/TypeQueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,85 @@ public TypeQueryBuilder<T> Facet(string propertyName)
$"{graphObject.Facets} {facet}";
return this;
}
/// <summary>
/// Get facet by field in a nested object
/// </summary>
/// <typeparam name="TField"></typeparam>
/// <param name="fieldSelector"></param>
/// <param name="propertySelector"></param>
/// <returns></returns>
public TypeQueryBuilder<T> Facet<TField>(Expression<Func<T, IEnumerable<TField>>> fieldSelector, Expression<Func<TField, string>> propertySelector)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
propertySelector.ValidateNotNullArgument("propertySelector");

Facet($"{fieldSelector.GetFieldPath()}.{propertySelector.GetFieldPath()}");
return this;
}

/// <summary>
/// Get facet by field in a nested object
/// </summary>
/// <typeparam name="TField"></typeparam>
/// <param name="fieldSelector"></param>
/// <param name="propertySelector"></param>
/// <returns></returns>
public TypeQueryBuilder<T> Facet<TField>(Expression<Func<T, IEnumerable<TField>>> fieldSelector, Expression<Func<TField, bool>> propertySelector)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
propertySelector.ValidateNotNullArgument("propertySelector");

Facet($"{fieldSelector.GetFieldPath()}.{propertySelector.GetFieldPath()}");
return this;
}

/// <summary>
/// Get facet by field in a nested object
/// </summary>
/// <typeparam name="TField"></typeparam>
/// <param name="fieldSelector"></param>
/// <param name="propertySelector"></param>
/// <returns></returns>
public TypeQueryBuilder<T> Facet<TField>(Expression<Func<T, IEnumerable<TField>>> fieldSelector, Expression<Func<TField, int>> propertySelector)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
propertySelector.ValidateNotNullArgument("propertySelector");

Facet($"{fieldSelector.GetFieldPath()}.{propertySelector.GetFieldPath()}");
return this;
}

/// <summary>
/// Get facet by field in a nested object
/// </summary>
/// <typeparam name="TField"></typeparam>
/// <param name="fieldSelector"></param>
/// <param name="propertySelector"></param>
/// <returns></returns>
public TypeQueryBuilder<T> Facet<TField>(Expression<Func<T, IEnumerable<TField>>> fieldSelector, Expression<Func<TField, DateTime>> propertySelector)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
propertySelector.ValidateNotNullArgument("propertySelector");

Facet($"{fieldSelector.GetFieldPath()}.{propertySelector.GetFieldPath()}");
return this;
}

/// <summary>
/// Get facet by field in a nested object
/// </summary>
/// <typeparam name="TField"></typeparam>
/// <param name="fieldSelector"></param>
/// <param name="propertySelector"></param>
/// <returns></returns>
public TypeQueryBuilder<T> Facet<TField>(Expression<Func<T, IEnumerable<TField>>> fieldSelector, Expression<Func<TField, object>> propertySelector)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
propertySelector.ValidateNotNullArgument("propertySelector");

Facet($"{fieldSelector.GetFieldPath()}.{propertySelector.GetFieldPath()}");
return this;
}
public TypeQueryBuilder<T> Total(bool? isAll = null)
{
if (!isAll.HasValue)
Expand Down

0 comments on commit 47dd57f

Please sign in to comment.