C# SolrNet-分面搜索错误结果
我有以下课程:C# SolrNet-分面搜索错误结果,c#,asp.net,entity-framework,solrnet,faceted-search,C#,Asp.net,Entity Framework,Solrnet,Faceted Search,我有以下课程: public class Product { public Product() { Categories = new List<Category>(); } [SolrUniqueKey("id")] public int Id { get; set; } [SolrField("name")] public string Name { get; set; } [SolrField(
public class Product
{
public Product()
{
Categories = new List<Category>();
}
[SolrUniqueKey("id")]
public int Id { get; set; }
[SolrField("name")]
public string Name { get; set; }
[SolrField("cat")]
public virtual List<Category> Categories { get; set; }
}
公共类产品
{
公共产品()
{
类别=新列表();
}
[SolrUniqueKey(“id”)]
公共int Id{get;set;}
[索尔菲尔德(“姓名”)]
公共字符串名称{get;set;}
[索尔菲尔德(“猫”)]
公共虚拟列表类别{get;set;}
}
现在我用100种产品填充solr。
产品的名称基于testitem[i],其中i是产品的编号。(0-99)
现在,这同样适用于类别,它们工作得很好。但当我要求在名称中使用facet时,我得到了以下结果:
<int name="testitem">100</int>
<int name="0">1</int>
<int name="1">1</int>
<int name="10">1</int>
<int name="11">1</int>
<int name="12">1</int>
<int name="13">1</int>
<int name="14">1</int>
<int name="15">1</int>
<int name="16">1</int>
etc..
100
1.
1.
1.
1.
1.
1.
1.
1.
1.
等
正如你所看到的,这是不对的。看起来solr将数字从字符串中拆分出来。奇怪的是,这并没有发生在分类方面
有人知道哪里出了问题/我做错了。这很可能是因为索引中的
名称字段使用了Solr字段类型。如果仔细查看schema.xml中的名称的字段类型
定义,很可能是text\u general
,这些字段将您输入的值标记化,因此这就是将您的名称值拆分为文本和数字值的原因。在这种情况下,我建议使用一个单独的字段来存储刻面值,并使用指令将名称值移动到这个新字段
所以你的模式看起来像这样
<field name="name" type="text_general" stored="true" indexed="true" />
<field name="name_facet" type="string" stored="true" indexed="true" />
<copyField source="name" dest="name_facet" />
然后对name_facet字段运行facet查询,您应该会看到预期的结果。谢谢,我是Solr的新手,不知道所有字段也需要在schema.xml中指定。更改了我的模式,现在它工作得很好。谢谢如果我使用copy字段,那么它是否在solrnet类中声明???或者只是改变模式就行了..@DharmikBhandari您需要同时更新两者。将copyField指令添加到您的模式中,然后如果您想在Solr的结果中访问该copyField中的值,您还需要将其添加到solrnet类中,除非您使用的是catch all映射,如字典映射和动态字段部分下的条目所示。感谢您的快速回复。我在Suggester中使用了复制字段。但建议时未获取索引数据。复制字段有问题吗???没有,Suggester有不同的行为,它只会根据您的设置向您显示建议。如果要检索索引数据,则需要运行常规查询,而不是建议查询。