0

Sitecore 8.1, Lucene index.

I have a (Glass) field marked with [SitecoreIgnore] that I would like to be populated with values from the index.

More specifically, the index has a number of strings that represent GUIDs; I would like this field to be an IEnumerable of Sitecore Items, with their GUID coming from the index. Is this possible out of the box?

1

Yes, in your index model you can use TypeConverter attribute with type Sitecore.ContentSearch.Converters.IndexFieldEnumerableConverter parameter to map guids from index to the Items IEnumerable in the following manner:

public class IndexResultItem : SearchResultItem
{
    [IndexField("_myfield")]
    [TypeConverter(typeof(IndexFieldEnumerableConverter))]
    public IEnumerable<Item> Items { get; set; }
}
  • Hi Andrei! Thanks for your answer - are you sure this works with Glass wrappers? In my experience it only does with Guids and not more complex types. – Emanuele Ciriachi Jan 21 at 14:01
  • Welcome, Emanuele Ciriachi. No, this is not actually a part of the glassmapper, this is a part of Lucene search, as glassmapper have no relation to the search. So, in your case, I would use glasmapper model and search model separately. In the glass model class you can create a property (not mapped to the sitecore field: with [SitecoreIgnore]) which later will be filled from search model, so, after glass model is created(mapped to the sitecore item) and search is done, you can fill this property : glassModel.CustomItems = indexModel.Items – Andrei Akonnikau Jan 21 at 14:35

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.