I am using solr 4.6 with Jetty and as a client latest solrnet build (1672). I haven't done any changes to solrconfig.xml or schema.xml, because all I need is content and id of the document. My class is:
public class Register
{
[SolrUniqueKey("id")]
public string Id { get; set; }
[SolrField("content")]
public string Content { get; set; }
[SolrField("text")]
public string Text{get;set;}
}
I insert documents into solr with code:
using (FileStream fileStream = File.OpenRead(filePath))
{
var response =
Solr.Extract(
new ExtractParameters(fileStream, txtId.Text)
{
ExtractFormat = ExtractFormat.Text,
ExtractOnly = false,
});
}
Solr.Commit();
My problem is that I can't make highlights to work. My code for highlightning:
QueryOptions options =
new QueryOptions{Highlight = new HighlightingParameters{Fields = new[] {"id", "content", "text"}}};
SolrQueryByField query = new SolrQueryByField("text", "nhibernate");
var res = Solr.Query(query, options);
When the third line is executed I am receiving an error:
{"Could not convert value 'System.Collections.ArrayList' to property 'Content' of document type SolrTest.Register"}
What could be wrong here? I have followed this link
Your issue is that in the default schema.xml file, the field content
is defined with multiValued=true
. Telling Solr to allow multiple values for this field within a single document, e.g. stored as an array. So you need to change the Content property in your Register class to the following:
[SolrField("content")]
public ICollection<string> Content { get; set; }
As shown in the SolrNet Mapping documentation.