Skip to content
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using VirtoCommerce.ExperienceApiModule.Core.Binding;
using VirtoCommerce.SearchModule.Core.Model;
Expand All @@ -10,11 +11,19 @@ public class VariationsBinder : IIndexModelBinder

public virtual object BindModel(SearchDocument searchDocument)
{
var fieldName = BindingInfo.FieldName;
if (!searchDocument.TryGetValue(BindingInfo.FieldName, out var value))
{
return new List<string>();
}

return searchDocument.ContainsKey(fieldName) && searchDocument[fieldName] is object[] objs
? objs.Select(x => (string)x).ToList()
: Enumerable.Empty<string>().ToList();
// It is important to note that not all search engines, such as Lucene, support field types as collections,
// so they may not return an array for single value
return value switch
{
IEnumerable<object> objs => objs.Select(x => x.ToString()).ToList(),
string s => [s],
_ => []
};
}
}
}
Loading