I have created an index field called "facetCategory".
public class IndexResultModel : SearchResultItem
{
[IndexField("facetcategory_sm")]
public IList<Guid> FacetCategory { get; set; }
}
I am using search API and passing comma seperated guids to search.I am using the following code to retirve the results where FacetCategory contains list of Guids.
try
{
var query = context.GetQueryable<IndexResultModel >();
var containsQuery = PredicateBuilder.True<IndexResultModel >();
if (!string.IsNullOrEmpty(filters))
{
var facets = filters.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string facet in facets)
{
containsQuery = containsQuery.Or(item => item.FacetCategory.Contains(new Guid(facet)));
}
//join the predicate and the containsQuery
predicate = predicate.And(containsQuery);
}
query = query.Where(predicate);
if (latitude != 0 && longitude != 0)
{
query = query.WithinRadius(i => i.GeoLoc, latitude, longitude, distance).OrderByNearest();
}
if (currentPage > 0 && resultPerPage > 0)
{
Results = query.Skip((currentPage - 1) * currentPage).Take(resultPerPage).ToList();
}
else
{
Results = query.ToList();
}
}
catch (Exception)
{
}
I am getting an error because of adding the below code to search code
containsQuery = containsQuery.Or(item => item.FacetCategory.Contains(new Guid(facet)));
The error says "Unsupported expression node type: MemberAccess within type constructor parameter". I have tried the other index fields which are string or integer and it works fine but because facetcategory_sm type is IList, it can not query contains guids.
here is screenshot of the field being indexed in Solr
List<string>
instead ofIList<Guid>