因此,我启动并运行了一个 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"/>
[...]
我搜索了一些关于如何设置所有东西的示例,并提出了一个用于映射值的 Product-Class(还有一些值,但为了获得图片,我认为这已经足够了),如下所示:
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”类型。即使在互联网上搜索该问题并调试程序后,我仍然不明白异常。“LampCount”是一个多值字段(Lucene 索引中的前 NumericField),其 schema.xml 和 Product.cs 中的映射应该可以工作。
它在 localhost:8983/solr/admin/ 上使用 web 界面时有效,我可以将查询设为“LampCount:1”,它会返回一堆正确找到的文档。这可能是另一个问题,但是在所有“按原样设置”的情况下,Solr 网络界面的结果集 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);
这会是问题吗,因为我现在看不到大局,感觉完全迷失了。如果你能解开我的脑结,将不胜感激。;-)
提前致谢!