4
votes

I am just starting out using SOLR integration with Sitecore 7. I managed to follow some guides and built a "POCO" class (inheriting from SearchResultItem) which allows me to perform the LINQ queries and search data as shown in the sample below:

public class MySearchItem: SearchResultItem
{
    [IndexField("Text Field")]
    public string TextField
    {
        get;
        set;
    }

    [IndexField("Drop Link")]
    public ID DropLink
    {
        get;
        set;
    }

    [IndexField("Tree List")]
    public IEnumerable<ID> TreeList
    {
        get;
        set;
    }
}

When I get to perform a query, using the code below, I am observing the TextField and DropLink properties in the results item to be correctly populated, with the content and ID for TextField and DropLink respectively. The TreeList property is however being retrieved as null. I have checked the obvious and made sure that the hints correctly reflect the field name in the sitecore template, and according to the "Developer's Guide to Item Buckets and Search" document for sitecore 7 IEnumerable is supported automatically.

var index = ContentSearchManager.GetIndex("sitecore_master_index");

using (var context = index.CreateSearchContext())
{
    var results = context.GetQueryable<MySearchItem>();

    results = results.Where(item => item.TemplateName == "Custom Sitecore Template");
}

The field is located in the indexer since a call to results.First()["TreeList"] seems to show the data I'm after. Would this be the right approach in reading the data?

Furthermore, would it be at all possible to put in other types in my "POCO" class? Let's say I want to query the property of an item within the Tree List. How would I go about implementing this? Am I right in assuming that a TypeConverter for the type of my Tree List would be required for sitecore to correctly resolve the TreeList in a type other than the ID to do something like the below?

[IndexField("Tree List")]
public IEnumerable<TreeListItem> TreeList
{
    get;
    set;
}

Any help/guidance towards understanding this behavior would be greatly appreciated.

Thanks!

Update

I have filed this as a bug report as suggested in this post. In case anyone comes across this, they confirmed this is an issue and suggested the following workaround:

Add the following lines to the section of the Sitecore.ContentSearch.Solr.Indexes.config file:

<typeMatch typeName="guidCollection"      type="System.Collections.Generic.IEnumerable`1[System.Guid]"    fieldNameFormat="{0}_sm"  multiValued="true"   settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" /> 
<typeMatch typeName="stringCollection"    type="System.Collections.Generic.IEnumerable`1[System.String]"   fieldNameFormat="{0}_sm"  multiValued="true"   settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
<typeMatch typeName="intCollection"          type="System.Collections.Generic.IEnumerable`1[System.Int32]"     fieldNameFormat="{0}_im"   multiValued="true"   settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />

Hope this helps!

1

1 Answers

4
votes

I had the same issue and from inspecting the config file Sitecore.ContentSearch.Solr.Indexes.config it seems that the type is not mapped with the Solr Provider.

This is indeed weird as in the documentation Developer's Guide to Item Buckets and Search, it clearly states that out of the box it should be able to map types of IEnumerable<T>.

Can you please try changing the type of your multilist field from IEnumerable<ID> to List<Guid> instead and check if this solves your issue ?