Using Glass Mapper with Solr Sitecore 8
When using Solr search provider in Sitecore 8 and also using the excellent Glass mapper for Sitecore the documentation on the Glass site walks you through creating a custom search result class with property attributes for search and glass here
The ID property has the attribute [IndexField("_id")], this attribute does not work with Solr and should be replaced with [IndexField("_group")]
| using System; | |
| using System.ComponentModel; | |
| using Glass.Mapper.Sc.Configuration; | |
| using Glass.Mapper.Sc.Configuration.Attributes; | |
| using System.Xml.Serialization; | |
| using Sitecore.ContentSearch; | |
| using Sitecore.ContentSearch.Converters; | |
| using Sitecore.Data; | |
| using Sitecore.Data.Items; | |
| namespace WesleyLomax.Common.Model.Base | |
| { | |
| [Serializable] | |
| public abstract class BaseSearchResultItem | |
| { | |
| [SitecoreId] | |
| [IndexField("_group")] | |
| public virtual Guid Id { get; set; } | |
| [SitecoreInfo(SitecoreInfoType.Language)] | |
| [IndexField("_language")] | |
| public virtual string Language { get; set; } | |
| [TypeConverter(typeof(IndexFieldItemUriValueConverter))] | |
| [XmlIgnore] | |
| [IndexField("_uniqueid")] | |
| public virtual ItemUri Uri { get; set; } | |
| [SitecoreInfo(SitecoreInfoType.Version)] | |
| public virtual int Version | |
| { | |
| get | |
| { | |
| return Uri == null ? 0 : Uri.Version.Number; | |
| } | |
| } | |
| [IndexField("_name")] | |
| public virtual string Name { get; set; } | |
| [IndexField("_template")] | |
| [TypeConverter(typeof(IndexFieldIDValueConverter))] | |
| public virtual ID TemplateId { get; set; } | |
| [IndexField("_uniqueid")] | |
| public virtual string UniqueId { get; set; } | |
| } | |
| } |
A quick look at the SearchResultItem class in the Sitecore.ContentSearch dll shows why.