简体   繁体   中英

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. The name of the products is based on testitem[i] where i is the number of the product. (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:

<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 . 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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