public void Sort_Adds_FieldNames_To_Output_Json() { var fields = new List<string> {"name", "-age"}; var searchParams = new SearchParams(); searchParams.Sort(fields.ToArray()); var result = searchParams.ToJson().ToString(Formatting.None); var expected = JsonConvert.SerializeObject(new { ctl = new { timeout = 75000 }, sort = fields }, Formatting.None); Assert.AreEqual(expected, result); }
/// <summary> /// Configures the list of fields which are used for sorting the search result. Fields with a prefix of "-" indicate a decending nature. /// If no sort is provided, it is equal to sort("-_score"), since the server will sort it by score in descending order by default. /// </summary> /// <param name="sort">The field names to sort by.</param> /// <returns></returns> public SearchQuery Sort(params string[] sort) { SearchParams.Sort(sort); return(this); }