1
votes

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.

2
I have working multivalue property with string[] type (array instead of derived List type).Matej
@Matej It works for me with string[], however I don't think I can use an array here. The derived List has got reasons for its existence.Srikanth Venugopalan

2 Answers

1
votes

I guess I figured out the reason - when indexed the multivalued entity is stored as an array and when deserialized it gets converted into an ArrayList. Hence, in my case the derived List cannot be used directly.

The lesson learnt is that I need to separate my domain model from my index model - which in retrospect sounds like a good practise.

1
votes

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.