Skip to content
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
5 changes: 5 additions & 0 deletions src/Models/GenericResponse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Stream.Models
Expand All @@ -7,6 +8,10 @@ public class GenericGetResponse<T> : ResponseBase
{
/// <summary>Container for <typeparamref name="T"/> objects.</summary>
public List<T> Results { get; set; }

/// <summary>The ranking expression used for scoring activities.</summary>
[JsonProperty("ranking_expr")]
public string RankingExpression { get; set; }
}

/// <summary>Base class for personalized read responses of <typeparamref name="T"/>.</summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Models/GetOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class GetOptions
private string _user_id = null;
private string _ranking_vars = null;
private bool _score_vars = false;
private bool _ranking_expr = false;
private string _discard_actors = null;
private string _discard_actors_sep = null;
private string _moderation_template = null;
Expand Down Expand Up @@ -68,6 +69,12 @@ public GetOptions WithScoreVars()
return this;
}

public GetOptions WithRankingExpr()
{
_ranking_expr = true;
return this;
}

public GetOptions WithRankingVars(IDictionary<string, object> rankingVars)
{
_ranking_vars = StreamJsonConverter.SerializeObject(rankingVars);
Expand Down Expand Up @@ -149,6 +156,9 @@ internal void Apply(RestRequest request)
if (_score_vars)
request.AddQueryParameter("withScoreVars", "true");

if (_ranking_expr)
request.AddQueryParameter("with_ranking_expr", "true");

if (!string.IsNullOrWhiteSpace(_discard_actors_sep))
request.AddQueryParameter("discard_actors_sep", _discard_actors_sep);

Expand Down
30 changes: 30 additions & 0 deletions tests/ActivityTests/GetActivityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,36 @@ public async Task TestScoreVars()
Assert.IsNull(r2.Results[0].ScoreVars);
}

[Test]
public async Task TestRankingExpression()
{
var feed = this.RankedFeed;

var newActivity1 = new Activity("1", "test", "1")
{
ForeignId = "r-test-1",
Time = DateTime.Parse("2000-08-16T16:32:32"),
};

newActivity1.SetData("popularity", 123);
var r1 = await feed.AddActivityAsync(newActivity1);

// Test with ranking expression flag
var r2 = await feed.GetFlatActivitiesAsync(GetOptions.Default.WithLimit(1).WithRanking("popularity").WithRankingExpr());
Assert.IsNotNull(r2.RankingExpression);
Assert.IsNotEmpty(r2.RankingExpression);

// Test without ranking expression flag
r2 = await feed.GetFlatActivitiesAsync(GetOptions.Default.WithLimit(1).WithRanking("popularity"));
Assert.IsNull(r2.RankingExpression);

// Test with both score vars and ranking expression
r2 = await feed.GetFlatActivitiesAsync(GetOptions.Default.WithLimit(1).WithRanking("popularity").WithScoreVars().WithRankingExpr());
Assert.IsNotNull(r2.RankingExpression);
Assert.IsNotEmpty(r2.RankingExpression);
Assert.IsNotNull(r2.Results[0].ScoreVars);
}

[Test]
public async Task TestGetActivitiesByForeignIDAndTime()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Setup()
FlatFeed = Client.Feed("flat", System.Guid.NewGuid().ToString());
AggregateFeed = Client.Feed("aggregate", System.Guid.NewGuid().ToString());
NotificationFeed = Client.Feed("notification", System.Guid.NewGuid().ToString());
RankedFeed = Client.Feed("ranked", System.Guid.NewGuid().ToString());
RankedFeed = Client.Feed("user", System.Guid.NewGuid().ToString());
}
}
}
Loading