0

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.

Julian
  • 1,105
  • 2
  • 26
  • 57

1 Answers1

2

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.

Paige Cook
  • 22,415
  • 3
  • 57
  • 68
  • Thanks, I'm new to Solr and didn't know all the fields also need to be specified in the schema.xml. Changed my schema and now it works perfect. Thanks! – Julian Jul 06 '12 at 07:34
  • if I use copy field then does it declare in solrnet class ??? or just change in schema and it will work..?? – Dharmik Bhandari Sep 17 '12 at 12:28
  • @DharmikBhandari you will need to update both. Add the copyField directive to your schema and then if you want to access the value in that copyField in your results from Solr, you will need to add it to your solrnet class as well, unless you use a catch all mapping as shown in the entry of http://code.google.com/p/solrnet/wiki/Mapping under the Dictionary Mappings and Dynamic Fields section. – Paige Cook Sep 17 '12 at 12:31
  • Thanks for quick reply.I've used copy field in Suggester. but did not get indexed data while suggestion. Is there something wrong with copy field ??? – Dharmik Bhandari Sep 17 '12 at 12:42
  • No, Suggester has different behavior in that it will only show you the suggestions based on your settings. If you want to retrieve indexed data, you will need to run a regular query and not a Suggester query. – Paige Cook Sep 17 '12 at 12:54