Reputation: 957
I my project I am using Sitecore7 MVC, Solr and Glass Mapper.
The "ContentSearch" index contains pretty much all the fields used in sitecore template. I am using GlassMapper classes as my Models (which contains pretty much nothing but properties that are sitecore fields) and querying on it. Basically doing "Using A Custom Result Class" as described here : http://glass.lu/docs/tutorial/sitecore/tutorial25/tutorial25.html
Which works as it is supposed to.
My question is:
Is it populating the class properties ( which are typically sitecore fields ) using Solr index as long as the index exists (which is what I want) ?
OR
Is it going to sitecore to get the Field Values ? (which I would think is inefficient and in which case I will write custom classes and loop over them to populate glassMapper classes because in my views I have used GlassMapper classes as my models)
For example one of my Models looks like this:
[SitecoreType]
public class MyAwesomeModel
{
[SitecoreId]
[IndexField("_id")]
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;
}
}
[SitecoreField(FieldName="MyRichtextField")]
[IndexField("MyRichtextField")]
public virtual string RichTextContent { get; set; }
[SitecoreInfo(SitecoreInfoType.Url, UrlOptions = SitecoreInfoUrlOptions.LanguageEmbeddingNever)]
public virtual string Url { get; set; }
}
Upvotes: 2
Views: 1327
Reputation: 804
I actually just pushed some code to my Fork of Glass.Mapper that does right that: https://github.com/csteeg/Glass.Mapper (in the develop branch)
You have to patch your config, so you'll use glass specific contentsearch settings:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<indexConfigurations>
<defaultLuceneIndexConfiguration type="Sitecore.ContentSearch.LuceneProvider.LuceneIndexConfiguration, Sitecore.ContentSearch.LuceneProvider">
<indexDocumentPropertyMapper>
<objectFactory type="Sitecore.ContentSearch.DefaultDocumentMapperObjectFactory, Sitecore.ContentSearch">
<patch:attribute name="type">Glass.Mapper.Sc.ContentSearch.LuceneProvider.GlassDocumentMapperObjectFactory, Glass.Mapper.Sc.ContentSearch.LuceneProvider</patch:attribute>
</objectFactory>
</indexDocumentPropertyMapper>
</defaultLuceneIndexConfiguration>
</indexConfigurations>
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
<indexes hint="list:AddIndex">
<index id="sitecore_master_index">
<patch:attribute name="type">Glass.Mapper.Sc.ContentSearch.LuceneProvider.GlassLuceneIndex, Glass.Mapper.Sc.ContentSearch.LuceneProvider</patch:attribute>
</index>
<index id="sitecore_web_index">
<patch:attribute name="type">Glass.Mapper.Sc.ContentSearch.LuceneProvider.GlassLuceneIndex, Glass.Mapper.Sc.ContentSearch.LuceneProvider</patch:attribute>
</index>
<index id="sitecore_core_index">
<patch:attribute name="type">Glass.Mapper.Sc.ContentSearch.LuceneProvider.GlassLuceneIndex, Glass.Mapper.Sc.ContentSearch.LuceneProvider</patch:attribute>
</index>
</indexes>
</configuration>
</contentSearch>
</sitecore>
</configuration>
The code first returns values from the index, if they are stored there. If a property is requested that is not stored in the index, it will get the value from the Sitecore item
Upvotes: 5