3

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

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

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, privacy policy and cookie policy

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