Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Search] Add missing property when cloning SearchOptions #27582

Merged
merged 4 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Do not use reflection to copy over SearchOptions properties
  • Loading branch information
Mohit-Chakraborty committed Apr 11, 2022
commit 89e20cff83ac79b4346cd335b4530c65fbce8a49
31 changes: 27 additions & 4 deletions sdk/search/Azure.Search.Documents/src/Options/SearchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,33 @@ private static void Copy(SearchOptions source, SearchOptions destination)
Debug.Assert(source != null);
Debug.Assert(destination != null);

foreach (System.Reflection.PropertyInfo propertyInfo in typeof(SearchOptions).GetProperties())
{
propertyInfo.SetValue(destination, propertyInfo.GetValue(source));
}
destination.Facets = source.Facets;
destination.Filter = source.Filter;
destination.HighlightFields = source.HighlightFields;
destination.HighlightPostTag = source.HighlightPostTag;
destination.HighlightPreTag = source.HighlightPreTag;
destination.IncludeTotalCount = source.IncludeTotalCount;
destination.MinimumCoverage = source.MinimumCoverage;
destination.OrderBy = source.OrderBy;
destination.QueryAnswer = source.QueryAnswer;
destination.QueryAnswerCount = source.QueryAnswerCount;
destination.QueryCaption = source.QueryCaption;
destination.QueryCaptionHighlightEnabled = source.QueryCaptionHighlightEnabled;
destination.QueryLanguage = source.QueryLanguage;
destination.QuerySpeller = source.QuerySpeller;
destination.QueryType = source.QueryType;
destination.ScoringParameters = source.ScoringParameters;
destination.ScoringProfile = source.ScoringProfile;
destination.ScoringStatistics = source.ScoringStatistics;
destination.SearchFields = source.SearchFields;
destination.SearchMode = source.SearchMode;
destination.SearchText = source.SearchText;
destination.Select = source.Select;
destination.SemanticConfigurationName = source.SemanticConfigurationName;
destination.SemanticFields = source.SemanticFields;
destination.SessionId = source.SessionId;
destination.Size = source.Size;
destination.Skip = source.Skip;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,17 +1029,19 @@ public void SearchOptionsCanBeCopied()
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); // String value
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`
}
Expand Down