Content search in Sitecore PredicateBuilder vs IEnumerable

I am having a problem querying a computed index field IEnumerable. I am using Sitecore 7.2 upd2, Lucene, ContentSearch and PredicateBuilder.

I am trying to query the prices of products that are available in the product section. There is some heavy logic to find available products, so I decided to put all available prices of a product in the calculated area. Unfortunately, it looks like I cannot query the price list with PredicateBuilder.

My request looks like this:

predicate = predicate.And(p => p.Prices.Any(x => x >= priceFrom && x <= priceTo));

      

config field in index config:

<field fieldName="Prices"  storageType="YES" indexType="TOKENIZED"    vectorType="NO" boost="1f" type="System.Collections.Generic.IEnumerable`1[System.Int32]" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />

      

and that's my mistake:

Invalid Method Call Argument Type: Field - FieldNode - Field: prices -     System.Collections.Generic.IEnumerable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]. Only constant arguments is supported.

      

Any ideas?

+3


source to share


2 answers


The error is related to the parameter of the method call Any()

.



Searching for content in Sitecore LINQ has some limitations. One of these is that methods only accept "constant expressions" (objects) as parameters. You are passing the expression "lamda" as a parameter to the Any method.

+3


source


I would suggest indexing both the minimum and maximum price for each product as separate calculated fields (decimal) in the index.

This will greatly simplify your request:



var results = context.GetQueryable<ProductSearchResultItem>
    .Where(p => p.MinPrice >= myPrice)
    .Where(p => p.MaxPrice <= myPrice)
    .GetResults();

      

+1


source







All Articles