Skip to content

Commit

Permalink
feat(index): deprecate GetObjectIDPosition in favor of GetObjectPosition
Browse files Browse the repository at this point in the history
[changelog]
  • Loading branch information
aseure committed Aug 29, 2019
1 parent 7b6625c commit 0ecdf01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Algolia.Search.Test/EndToEnd/Index/SearchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public async Task SearchTestAsync()
Task.WaitAll(searchAlgoliaTask, searchElonTask, searchElonTask1, searchElonTask2, searchFacetTask);

Assert.That(searchAlgoliaTask.Result.Hits, Has.Exactly(2).Items);
Assert.That(searchAlgoliaTask.Result.GetObjectIDPosition("nicolas-dessaigne"), Is.EqualTo(0));
Assert.That(searchAlgoliaTask.Result.GetObjectIDPosition("julien-lemoine"), Is.EqualTo(1));
Assert.That(searchAlgoliaTask.Result.GetObjectIDPosition(""), Is.EqualTo(-1));
Assert.That(searchAlgoliaTask.Result.GetObjectPosition("nicolas-dessaigne"), Is.EqualTo(0));
Assert.That(searchAlgoliaTask.Result.GetObjectPosition("julien-lemoine"), Is.EqualTo(1));
Assert.That(searchAlgoliaTask.Result.GetObjectPosition(""), Is.EqualTo(-1));
Assert.That(searchElonTask.Result.QueryID, Is.Not.Null);
Assert.That(searchElonTask1.Result.Hits, Has.Exactly(1).Items);
Assert.That(searchElonTask2.Result.Hits, Has.Exactly(2).Items);
Expand Down
16 changes: 15 additions & 1 deletion src/Algolia.Search/Utils/AlgoliaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,30 @@ namespace Algolia.Search.Utils
/// </summary>
public static class AlgoliaHelper
{
/// <summary>
/// GetObjectPosition returns the position (0-based) within the `Hits`
/// result list of the record matching against the given `objectID`. If the
/// `objectID` is not found, `-1` is returned.
/// </summary>
/// <param name="objectID">ID of the record the check.</param>
/// <param name="searchResult">SearchResult to look in. </param>
public static int GetObjectPosition<T>(this SearchResponse<T> searchResult, string objectID) where T : class
{
return searchResult.Hits.FindIndex(x => GetObjectID(x).Equals(objectID));
}


/// <summary>
/// GetObjectIDPosition returns the position (0-based) within the `Hits`
/// result list of the record matching against the given `objectID`. If the
/// `objectID` is not found, `-1` is returned.
/// </summary>
/// <param name="objectID">ID of the record the check.</param>
/// <param name="searchResult">SearchResult to look in. </param>
[ObsoleteAttribute("This function will be deprecated. Use GetObjectPosition instead.")]
public static int GetObjectIDPosition<T>(this SearchResponse<T> searchResult, string objectID) where T : class
{
return searchResult.Hits.FindIndex(x => GetObjectID(x).Equals(objectID));
return GetObjectPosition<T>(searchResult, objectID);
}

/// <summary>
Expand Down

0 comments on commit 0ecdf01

Please sign in to comment.