简体   繁体   English

SolrNet - 分面搜索错误的结果

[英]SolrNet - Faceted search wrong results

I've got the following class: 我有以下课程:

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; }        
}

Now I fill solr with 100 products. 现在我给solr填写了100个产品。 The name of the products is based on testitem[i] where i is the number of the product. 产品名称基于testitem [i] ,其中i是产品编号。 (0-99). (0-99)。

Now this same goes for the categories, which work fine. 现在这同样适用于类别,这些工作正常。 But when I ask for facets in the name I get the following result: 但是当我在名称中要求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..

As you can see this isn't right. 如你所见,这是不对的。 It looks like solr splits the number from the string . 看起来solr会从字符串中分割出数字 The weird thing is that this doesn't happen in the category facet. 奇怪的是,这不会发生在类别方面。

Does anyone know what is going wrong / I'm doing wrong. 有谁知道出了什么问题/我做错了。

More than likely this is because of the Solr field type you are using for your name field in your index. 这很可能是因为您在索引中使用了您的name字段的Solr字段类型。 If you look closely at the fieldType definition in the schema.xml for the name , it is probably text_general and those fields tokenize the values you input into them, so that is what is splitting your name values into text and number values. 如果仔细查看schema.xml中的fieldType定义name ,它可能是text_general并且这些字段text_general您输入的值标记为它们,这就是将名称值拆分为文本和数字值的原因。 In this case, I would suggest using a separate field for storing the faceting values and use the Copy Field directive to move the name value to this new field. 在这种情况下,我建议使用单独的字段来存储分面值,并使用“ 复制字段”指令将名称值移动到此新字段。

So your schema would look something like this... 所以你的架构看起来像这样......

 <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" />

Then run your facet query against the name_facet field and you should see the expected results. 然后对name_facet字段运行facet查询,您应该看到预期的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM