gpt4 book ai didi

c# - Solr.Net 查询 : ArgumentException in Windows Forms

转载 作者:可可西里 更新时间:2023-11-01 09:38:29 24 4
gpt4 key购买 nike

所以我启动并运行了一个 Windows 窗体项目。它使用 Lucene.Net 库,我用它制作了一个 Lucene 索引。该程序接受用户请求,通过一些算法运行它们并在 DataGridView 中显示结果集。

之后我安装了 XAMPP,使用 Tomcat 服务来设置 Solr 3.6.1。我将 schema.xml 配置如下(感谢 Can a raw Lucene index be loaded by Solr? ):

<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
[...]
<field name="LuminaireId" type="string" indexed="true" stored="true"/>
<field name="LampCount" type="tdouble" multiValued="true" indexed="true" stored="true" required="false"/>
[...]

我搜索了一些关于如何设置所有东西的示例,并提出了一个用于映射值的产品类(还有一些值,但为了获得图片,我认为这就足够了),如下所示:

public class SolrProduct
{
[SolrUniqueKey("LuminaireId")]
public string LuminaireId { get; set; }

[SolrField("LampCount")]
public ICollection<double> LampCount { get; set; }
}

一个简单的测试查询(使用这个方法)

internal override List<KeyValuePair<Int64, Double>> CalculateRanking(List<T> checkedAttributes)
{
Startup.Init<SolrProduct>("http://localhost:8983/solr/");
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<SolrProduct>>();
var results = solr.Query("LampCount:1");
// as is: no mapping for result-return for now, returning "null" instead
return(null);
}

产生一个 ArgumentException,告诉我“System.Collections.ArrayList”类型的对象不能转换为“System.String”类型。即使在 Internet 上搜索该问题并调试程序后,我仍然不理解该异常。 “LampCount”是一个多值字段(以前是 Lucene 索引中的 NumericField),它应该可以在 Product.cs 中使用 schema.xml 和映射。

在 localhost:8983/solr/admin/上使用 Web 界面时,它可以工作,我可以将查询发送为“LampCount:1”,它会返回一堆正确找到的文档。这可能是另一个问题,但是对于所有“按原样设置”,Solr Web 界面的结果集 XML 显示(在每个找到的文档中):

<arr name="LampCount">
<str>ERROR:SCHEMA-INDEX-MISMATCH,stringValue=1</str>
</arr>

我为 Lucene 索引文档索引了 LampCount 字段

 var valueField = new NumericField(internalname, Field.Store.YES, true);
valueField.SetDoubleValue(value);
doc.Add(valueField);

这会是问题所在吗,因为我现在看不到大局,感到完全迷失了。如果你能解开我的脑结,我将不胜感激。 ;-)

提前致谢!

最佳答案

您的架构与 POCO 不匹配。基本上,Solr 试图将“tdouble”字段类型转换为您的集合。你能做的最好的事情就是执行,你在管理控制面板和观察者中的查询返回了什么,然后问问自己你认为它将如何处理返回到你的 POCO 中的输入。

关于c# - Solr.Net 查询 : ArgumentException in Windows Forms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12027451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com