I recommend to use ComputedIndexField for your case.
Computed fields are a great way of storing calculated information while Sitecore indexes your items as opposed to using more resource to calculate it on the fly for use in your sublayouts/layouts.
public class ColorField: AbstractComputedIndexField
{
public string FieldName { get; set; }
public string ReturnType { get; set; }
public override object ComputeFieldValue(IIndexable indexable)
{
var item = indexable as SitecoreIndexableItem;
MultilistField f = item.Fields["Colors"];
if (f != null)
{
var multilist = f.GetItems();
if (multilist == null || multilist.Length == 0)
return null;
return string.Join(" ", multilist.Select(t => t["Name"]));
}
return null;
}
}
You need to register your custom computed field :
<fields hint="raw:AddComputedIndexField">
<field fieldName="colorcustomfield" returnType="string">YourNamespace.ColorField,YourAssembly</field>
</fields>
You need to extend SearchResult item class :
public class CustomSearchResultItem
{
[IndexField("colorcustomfield")]
public virtual string ColorField { get; set; }
}
You can use my code if you want to search for Color in a multilist field
var index = ContentSearchManager.GetIndex(indexName);
using (var context = index.CreateSearchContext())
{
var query = context.GetQueryable<CustomSearchResultItem>()
.Where(item => item.ColorField.Contains("Red"))
.ToList();
}