Search code examples
c#solrnet

Solrnet: unable to retrieve multivalue field from Solr


I have a model similar to below

public class Product
{
    [SolrUniqueKey("id")]
    public int ID { get; set; }
    [SolrField("storage")]
    public string Storage { get; set; }
    [SolrField("components")]
    public Components Components { get; set; }
}

public class Components : List<string>
{
    public Components()
    {}
    public Components(string[] components)
    {
        AddRange(components);
    }
}

In my schema.xml I map the fields as:

   <field name="id" type="string" indexed="true" stored="true" required="true" /> 
   <field name="storage" type="string" indexed="true" stored="true" omitNorms="true"/>
   <field name="components" type="text_ws" stored="true" multiValued="true" omitNorms="true"/>

I've added a list of 5 products to Solr index. If I query from Solr admin page for "*", I get this response doc for one of the results:

<doc>
  <arr name="components">
    <str>blah1</str>
    <str>blah2</str>
    <str>blah3</str>
  </arr>
  <str name="id">0</str>
  <str name="storage">foo</str>
</doc>

However, when I query Solr via Solrnet using something like:

private readonly ISolrReadOnlyOperations solr var results = solr.Query(SolrQuery.All);

I find that Components is always null.

Any help is appreciated.

I can see this behaviour for any derived collection.


Solution

  • You could do this with a 'proxy' property, as explained in this answer. Or you could write a ISolrFieldParser / ISolrFieldSerializer for your Components type.

    Independently of this, I agree that separating your domain model from the index model is usually a good idea.