Skip to content

Commit

Permalink
[Search] Add missing property when cloning SearchOptions (#27582)
Browse files Browse the repository at this point in the history
* Use reflection to clone `SearchOptions`
Copy all properties using reflection to alleviate missing some properties being copied

* Simplify code by using `PropertyInfo` efficiently

* Add a test for `SearchOptions` clone method

* Do not use reflection to copy over `SearchOptions` properties
  • Loading branch information
Mohit-Chakraborty authored Apr 13, 2022
1 parent b30fa6d commit bbef704
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ private static void Copy(SearchOptions source, SearchOptions destination)
destination.Select = source.Select;
destination.SemanticConfigurationName = source.SemanticConfigurationName;
destination.SemanticFields = source.SemanticFields;
destination.SessionId = source.SessionId;
destination.Size = source.Size;
destination.Skip = source.Skip;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,34 @@ await resources.GetQueryClient().SearchAsync<Hotel>(
ids);
}

[Test]
public void SearchOptionsCanBeCopied()
{
SearchOptions source = new();

source.Facets = new List<string> { "facet1", "facet2" };
source.Filter = "searchFilter";
// source.IncludeTotalCount = null;
source.QueryCaptionHighlightEnabled = false;
// source.QueryType = null;
source.Select = null;
source.SessionId = "SessionId";
source.Size = 100;
source.Skip = null;

SearchOptions clonedSearchOptions = source.Clone();

CollectionAssert.AreEquivalent(source.Facets, clonedSearchOptions.Facets); // A non-null collection with multiple items
Assert.AreEqual(source.Filter, clonedSearchOptions.Filter); // A string value
Assert.IsNull(clonedSearchOptions.IncludeTotalCount); // An unset bool? value
Assert.AreEqual(source.QueryCaptionHighlightEnabled, clonedSearchOptions.QueryCaptionHighlightEnabled); // A bool? value
Assert.IsNull(source.QueryType); // An unset enum? value
Assert.IsNull(clonedSearchOptions.Select); // A `null` collection
Assert.AreEqual(source.SessionId, clonedSearchOptions.SessionId); // A string value
Assert.AreEqual(source.Size, clonedSearchOptions.Size); // An int? value
Assert.IsNull(clonedSearchOptions.Skip); // An int? value set as `null`
}

/* TODO: Enable these Track 1 tests when we have support for index creation
protected void TestCanSearchWithDateTimeInStaticModel()
{
Expand Down

0 comments on commit bbef704

Please sign in to comment.