我不确定solrNet中是否有错误或我做错了什么。所以在我进入细节之前,首先是高级细节。
我在做什么:运行solr.Query(SearchText)命令。
错误:“System.Collections.ArrayList”类型的对象无法转换为“System.String”类型。
现在细节......
我可以使用solr.Net在Solr中非常愉快地创建文档,并且可以使用
进行搜索“HTTP://本地主机:8080 / solr的/选择/”
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
正如您所看到的,我正在尝试三种方法从索引中获取项目。
在SolrNet的幕后,它正在向solr发出以下请求
2012年9月19日下午1:08:21 org.apache.solr.core.SolrCore执行INFO:[] webapp = / solr path = / select / PARAMS = {Q = flutr_EventMarketURI: “足球/欧洲/英格兰/英超联赛+ / 2012/09 /第22 /斯旺西+市+ - +埃弗顿+ FC /与” &amp; =安培;行=亿} hits = 1 status = 0 QTime = 0
这意味着solr正在返回数据,但在执行solrNettyty的过程中,这个错误会冒泡。 - 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
作为参考,这是solr返回的内容
“HTTP://本地主机:8080 / solr的/选择/ Q = flutr_EventMarketURI:%22Football /欧洲/英格兰/超级+联赛/ 2012/09/22 /斯旺西+市+ - +埃弗顿+ FC /%22安培;? ?=安培;行=亿“
<?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>
这是我的班级
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();
}
}
有什么想法吗?
非常感谢。
由于
答案 0 :(得分:5)
您的问题是SolrFlurItem类中的文本字段被定义为字符串,但在solr中,您已将text
字段定义为multiValued="true"
,这允许在solr文档中包含多个条目,并且在您的solr返回值中显示。错误消息显示此不匹配,因为它无法将字符串数组映射到单个字符串中。
因此,您需要将此字段的定义更改为如下所示的集合:
[SolrField("text")]
public ICollection<string> text { get; set; }
您可以在SolrNet Wiki - Mapping部分中看到此示例以及其他用于将类映射到Solr结果的示例。