Implementing Random sort criteria in Projector

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-12-13 16:46:26 -08:00
parent caae84f07f
commit 786657d442
4 changed files with 6 additions and 10 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
ec573e5476f7e8a5a61593d6393e9985e9484fcc src/Orchard.Web/Modules/Orchard.Forms ec573e5476f7e8a5a61593d6393e9985e9484fcc src/Orchard.Web/Modules/Orchard.Forms
09ddede21aceaf0f403aae2ed84f479818f7b3af src/Orchard.Web/Modules/Orchard.Projections e89c4fadfb710e2f733b74665b0c176829f6b992 src/Orchard.Web/Modules/Orchard.Projections
01b83c05050bb731d9f69256bbe8884d458ea1c9 src/Orchard.Web/Modules/Orchard.Rules 01b83c05050bb731d9f69256bbe8884d458ea1c9 src/Orchard.Web/Modules/Orchard.Rules
65057c6a5cd71f7994ba9bcbeece50dbb737620e src/Orchard.Web/Modules/Orchard.TaskLease 65057c6a5cd71f7994ba9bcbeece50dbb737620e src/Orchard.Web/Modules/Orchard.TaskLease
c2e3c396c1fc6c60b131bfc9f83564c6f8d18e58 src/Orchard.Web/Modules/Orchard.Tokens c2e3c396c1fc6c60b131bfc9f83564c6f8d18e58 src/Orchard.Web/Modules/Orchard.Tokens
@@ -941,14 +941,12 @@ namespace Orchard.Tests.ContentManagement {
var firstResults = new List<int>(); var firstResults = new List<int>();
var rand = new Randomizer(123);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
result = _manager.HqlQuery().Join(alias => alias.ContentPartRecord<LambdaRecord>()).OrderBy(x => x.Named("civ"), order => order.Random(rand.Next(1000))).List(); result = _manager.HqlQuery().Join(alias => alias.ContentPartRecord<LambdaRecord>()).OrderBy(x => x.Named("civ"), order => order.Random()).List();
firstResults.Add(result.First().As<LambdaPart>().Record.IntegerStuff); firstResults.Add(result.First().As<LambdaPart>().Record.IntegerStuff);
} }
Assert.That(result.Distinct().Count(), Is.GreaterThan(1)); Assert.That(firstResults.Distinct().Count(), Is.GreaterThan(1));
} }
[Test] [Test]
@@ -228,7 +228,7 @@ namespace Orchard.ContentManagement {
sort.Item2(sortFactory); sort.Item2(sortFactory);
if (sortFactory.Randomize) { if (sortFactory.Randomize) {
sb.Append(" rand(" + sortFactory.Seed + ")"); sb.Append(" newid()");
} }
else { else {
sb.Append(sort.Item1.Name).Append(".").Append(sortFactory.PropertyName); sb.Append(sort.Item1.Name).Append(".").Append(sortFactory.PropertyName);
@@ -349,7 +349,6 @@ namespace Orchard.ContentManagement {
public bool Ascending { get; set; } public bool Ascending { get; set; }
public string PropertyName { get; set; } public string PropertyName { get; set; }
public bool Randomize { get; set; } public bool Randomize { get; set; }
public int Seed { get; set; }
public void Asc(string propertyName) { public void Asc(string propertyName) {
PropertyName = propertyName; PropertyName = propertyName;
@@ -361,8 +360,7 @@ namespace Orchard.ContentManagement {
Ascending = false; Ascending = false;
} }
public void Random(int seed) { public void Random() {
Seed = seed;
Randomize = true; Randomize = true;
} }
} }
+1 -1
View File
@@ -176,7 +176,7 @@ namespace Orchard.ContentManagement {
/// <summary> /// <summary>
/// Sorts randomly /// Sorts randomly
/// </summary> /// </summary>
void Random(int seed); void Random();
} }
} }