5

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

enter image description here

3
  • Can you share a screenshot how the list of guid appears on the solr when you query it directly on the solr server? Jun 8, 2018 at 23:42
  • @HishaamNamooya I have added the screenshot of the fields being indexed in Solr in the post. Jun 9, 2018 at 0:12
  • Can you try to put it as List<string> instead of IList<Guid> Jun 9, 2018 at 8:32

1 Answer 1

9

You need to create your Guid variable first before trying to filter FacetCategory on it, Something like:

Guid facetGuid = new Guid(facet);
containsQuery = containsQuery.Or(item => item.FacetCategory.Contains(facetGuid))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.