I am using VS2012, .NET 4.5 and SolrNet. I am struggling with solrnet mappings. I've succesfully started Apache Solr with jetty on http://localhost:8983/solr. My class which I want to add to solr is:

public class Register
{
    [SolrUniqueKey("id")]
    public string Id { get; set; }

    [SolrField("body")]  
    public string Body { get; set; }
}

I succesfully connect to solr, but I can't put my document into it:

Startup.Init<Register>(solrAddress);
Solr = ServiceLocator.Current.GetInstance<ISolrOperations<Register>>();   

var reg = new Register
                    { 
                        Id = "SP2514N",                       
                        Body = @"Dosel je prosel"
                    };               

                Solr.Add(reg);
                Solr.Commit(); 

Here I receive error, that 'body' is unknown field. I've also used MappingManager, like this:

var mgr = new MappingManager();
            var property = typeof(Register).GetProperty("Id");
            mgr.Add(property, "id");
            mgr.SetUniqueKey(property);
            mgr.Add(typeof(Register).GetProperty("Body"), "body");

But, again, my field was not mapped. What am I doing wrong? Isn't the mapping to solr supposed to be done through code? Do I need a special xml file?

有帮助吗?

解决方案

You need to confirm that you have a body field defined in your schema. If you are just using the default schema that comes with Solr, it does not include a body field. You can copy an existing similar entry in the schema.xml file, like description to get you going.

For more reference on configuring the Solr schema please refer to the following:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top