I am not sure if there is a bug within solrNet or I am doing something wrong. So first high level details before I jump into the detail.
What I am doing: Running a solr.Query(SearchText) command.
Error: Object of type 'System.Collections.ArrayList' cannot be converted to type 'System.String'.
Now the detail...
I am able to create documents quite happily in Solr with solr.Net and can search using
"http://localhost:8080/solr/select/?"
SolrQueryByField sq1 = SolrNet.DSL.Query.Field("flutr_EventMarketURI").Is(sfi.flutr_EventMarketURI);
SolrQuery sq2 = SolrNet.DSL.Query.Simple("flutr_EventMarketURI:\""+ sfi.flutr_EventMarketURI + "\"");
SolrQueryByField sq3 = new SolrQueryByField("flutr_EventMarketURI", sfi.flutr_EventMarketURI);
ISolrQueryResults<SolrFlutrItem> results = solr.Query(sq1); //Tried all three and same result
As you can see I am trying three ways to get an item back from the index.
Behind the scene with SolrNet it is firing off the following request to solr
Sep 19, 2012 1:08:21 PM org.apache.solr.core.SolrCore execute INFO: [] webapp=/solr path=/select/ params={q=flutr_EventMarketURI:"Football/Europe/England/Premier+League/2012/09/22/Swansea+City+-+Everton+FC/"&?=&rows=100000000} hits=1 status=0 QTime=0
This means that solr is returning the data but somewhere in the midst of doing solrNet'ty stuff this error bubbles up. - ISolrQueryResults results = solr.Query(sq1);
[ArgumentException: Object of type 'System.Collections.ArrayList' cannot be converted to type 'System.String'.]
System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) +4074070
System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) +9636530
System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) +151
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +223
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) +101
System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) +25
SolrNet.Impl.DocumentPropertyVisitors.RegularDocumentVisitor.Visit(Object doc, String fieldName, XmlNode field) in c:\prg\SolrNet\svn\SolrNet\Impl\DocumentPropertyVisitors\RegularDocumentVisitor.cs:48
SolrNet.Impl.DocumentPropertyVisitors.AggregateDocumentVisitor.Visit(Object doc, String fieldName, XmlNode field) in c:\prg\SolrNet\svn\SolrNet\Impl\DocumentPropertyVisitors\AggregateDocumentVisitor.cs:37
SolrNet.Impl.DocumentPropertyVisitors.DefaultDocumentVisitor.Visit(Object doc, String fieldName, XmlNode field) in c:\prg\SolrNet\svn\SolrNet\Impl\DocumentPropertyVisitors\DefaultDocumentVisitor.cs:39
SolrNet.Impl.SolrDocumentResponseParser`1.ParseDocument(XmlNode node, ICollection`1 fields) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrDocumentResponseParser.cs:65
SolrNet.Impl.SolrDocumentResponseParser`1.ParseResults(XmlNode parentNode) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrDocumentResponseParser.cs:50
SolrNet.Impl.ResponseParsers.ResultsResponseParser`1.Parse(XmlDocument xml, SolrQueryResults`1 results) in c:\prg\SolrNet\svn\SolrNet\Impl\ResponseParsers\ResultsResponseParser.cs:41
SolrNet.Impl.SolrQueryResultParser`1.Parse(String r) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrQueryResultParser.cs:46
SolrNet.Impl.SolrQueryExecuter`1.Execute(ISolrQuery q, QueryOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrQueryExecuter.cs:309
SolrNet.Impl.SolrBasicServer`1.Query(ISolrQuery query, QueryOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrBasicServer.cs:83
SolrNet.Impl.SolrServer`1.Query(ISolrQuery query, QueryOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrServer.cs:50
SolrNet.Impl.SolrServer`1.Query(ISolrQuery q) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrServer.cs:87
flutrClassLibrary.TSGCsolrHelper.GetFlutrItemViaURI(String solrURL, SolrFlutrItem sfi) in D:\Dropbox\aspDevelopment\flutrBetService\flutrClassLibrary\TSGCsolrHelper.cs:89
ReIndex.btnSendToSolr_Click(Object sender, EventArgs e) in d:\Dropbox\aspDevelopment\flutrBetService\flutrOddsAdmin\ReIndex.aspx.cs:97
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
As a reference, here is what solr returns
"http://localhost:8080/solr/select/?q=flutr_EventMarketURI:%22Football/Europe/England/Premier+League/2012/09/22/Swansea+City+-+Everton+FC/%22&?=&rows=100000000"
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
<lst name="params">
<str name="q">flutr_EventMarketURI:"Football/Europe/England/Premier League/2012/09/22/Swansea City - Everton FC/"</str>
<str name="?"/>
<str name="rows">100000000</str>
</lst>
</lst>
<result name="response" numFound="1" start="0">
<doc>
<str name="EventCategory">Football/Europe/England/Premier League</str>
<date name="EventDate">2012-09-22T11:45:00Z</date>
<date name="EventLastUpdated">2012-09-19T10:49:31Z</date>
<str name="EventName">Swansea City - Everton FC</str>
<str name="ResultsJSON">
{
"Category_name": "Football/Europe/England/Premier League",
"Event_name": "Everton FC - Southampton FC",
"Event_date": "2012-09-29T14:00:00",
"uri_event": "Football/Europe/England/Premier League/2012/09/29/Everton FC - Southampton FC/",
"Markets": [
{
"Market_name": "Match betting",
"Outcomes": [
{
"Outcome_name": "Everton FC",
"Odds": [
{
"Odds_decimal": "1.45",
"Last_updated_date": "2012-09-19T09:49:13.9144052Z",
"uri_odd": "Football/Europe/England/Premier League/2012/09/29/Everton FC - Southampton FC/Match betting/1/odd/bwin/"
}
],
"uri_outcome": "Football/Europe/England/Premier League/2012/09/29/Everton FC - Southampton FC/Match betting/1/"
},
{
"Outcome_name": "Southampton FC",
"Odds": [
{
"Odds_decimal": "6.45",
"Last_updated_date": "2012-09-19T09:49:13.9144052Z",
"uri_odd": "Football/Europe/England/Premier League/2012/09/29/Everton FC - Southampton FC/Match betting/1/odd/bwin/"
}
],
"uri_outcome": "Football/Europe/England/Premier League/2012/09/29/Everton FC - Southampton FC/Match betting/1/"
},
{
"Outcome_name": "Draw",
"Odds": [
{
"Odds_decimal": "4",
"Last_updated_date": "2012-09-19T09:49:13.9144052Z",
"uri_odd": "Football/Europe/England/Premier League/2012/09/29/Everton FC - Southampton FC/Match betting/X/odd/bwin/"
}
],
"uri_outcome": "Football/Europe/England/Premier League/2012/09/29/Everton FC - Southampton FC/Match betting/X/"
}
],
"uri_market": "Football/Europe/England/Premier League/2012/09/29/Everton FC - Southampton FC/Match betting/"
}
]
}
</str>
<str name="flutr_EventMarketURI">Football/Europe/England/Premier League/2012/09/22/Swansea City - Everton FC/</str>
<str name="flutr_ResultType">EVENT</str>
<arr name="text">
<str>Football/Europe/England/Premier League/2012/09/22/Swansea City - Everton FC/</str>
<str>Football/Europe/England/Premier League</str>
<str>Swansea City - Everton FC</str>
<str>Football/Europe/England/Premier League22/09/2012 11:45:00Swansea City - Everton FC1 , X , 2 , Match betting , Football/Europe/England/Premier League/2012/09/22/Swansea City - Everton FC/Match betting/ , </str>
</arr>
</doc>
</result>
</response>
Here is my class
public class SolrFlutrItem : ICloneable
{
public SolrFlutrItem() { }
[SolrUniqueKey("flutr_EventMarketURI")]
public string flutr_EventMarketURI { get; set; }
[SolrField("flutr_ResultType")]
public string flutr_ResultType { get; set; }
[SolrField("EventCategory")]
public string EventCategory { get; set; }
[SolrField("EventDate")]
public DateTime EventDate { get; set; }
[SolrField("EventLastUpdated")]
public DateTime EventLastUpdated { get; set; }
[SolrField("EventName")]
public string EventName { get; set; }
[SolrField("MarketName")]
public string MarketName { get; set; }
[SolrField("OutcomeName")]
public string OutcomeName { get; set; }
[SolrField("ResultsJSON")]
public string ResultsJSON { get; set; }
[SolrField("InternalJSON")]
public string InternalJSON { get; set; }
[SolrField("text")]
public string text { get; set; }
public object Clone()
{
return this.MemberwiseClone();
}
}
Any ideas?
Help much appreciated.
Thanks
Your issue is that the text field in your SolrFlurItem class is defined as a string, yet in solr you have defined the text
field as multiValued="true"
which allows for multiple entries in the solr document and is shown in your solr return value. The error message is showing this mis-match because it cannot map an array of strings into a single string.
So you need to change the definition of this field to a collection like the following:
[SolrField("text")]
public ICollection<string> text { get; set; }
You can see this example and others for mapping classes to Solr results with SolrNet in the SolrNet Wiki - Mapping section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With