I am currently trying to integrate Solrnet with a project I am working on and I am unable to even get Solrnet to produce a document from a populated POCO. Below is an example of the POCOs i'm using
public class Person : ICustomInterface
{
[SolrField("text")]
public string ContactNumber { get; set; }
[SolrField("text")]
public string ContactFax { get; set; }
[SolrField("text")]
public string ContactEmail { get; set; }
[SolrField("text")]
public string FamilyName { get; set; }
[SolrField("text")]
public string GivenName { get; set; }
[SolrField("text")]
public string MiddleName { get; set; }
[SolrField("text")]
public string Title { get; set; }
[SolrField("text")]
public string Gender { get; set; }
[SolrField("text")]
public string PlaceOfBirth { get; set; }
[SolrField("text")]
public string CountryOfBirth { get; set; }
[SolrUniqueKey("id")]
public string Id { get; set; }
}
I am calling the init function before I try and index the above using the following code.
Startup.Init<Person>("http://localhost:8080/solr-4.1.0");
I am then calling the following to try and index the object.
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Person>>();
solr.Add(mypoco);
solr.Commit();
The error on 'solr.Add(person)' is: "Document is missing mandatory uniqueKey field: id". Looking at the http request being sent, this makes sense, the body of the request is : <add><doc /></add>
.
It seems that no fields are getting picked up. Looking into it further, 'AttributesMappingManager' is return 0 results. Method is below and commented results I am seeing from 'GetPropertiesWithAttribute'.
var props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); //returns properties correctly
var kvAttrs = props.Select(prop => new KeyValuePair<PropertyInfo, T[]>(prop, type.GetCustomAttributes<T>())); // correct number of keys of properties with Solrnet attributes, but values are empty
var propsAttrs = kvAttrs.Where(kv => kv.Value.Length > 0); // 0 results
return propsAttrs; // 0 results
I have tried breaking this out into a test project and still get the same problems. I have tried with and without an interface and still no luck. I am probably missing something really simple, but would love to know what it is.
Note: I am using the latest version of Solrnet from the github repository
Update
Tested the 'SampleSolrApp' solution, fixed up some references (couldn't find SolrNet.DSL in 'HomeController.cs', SolrNet.DSL ref seemed to be missing, added reference from compiled github repo), sample seems to initialize correctly, posts 'exampledocs' via the AddInitialDocuments()
method on Application_Start. That works, however, shortly after I get the error "The given key was not present in the dictionary." within 'HtmlHelperMapperExtensions.cs'. The 'Product' object does have the correct attributes, with the field name the mapper is looking for, but can't find any fields('cat' in this case). This matches my problem I am having as it is not constructing a valid http request for solr because it can't seem to find the SolrField attributes.
Going to test the sample on another PC to see if this problem is something to do with my dev environment. Any advice or suggestions would be appreciated.
Update 2
Tested on another dev environment and I am getting the same error. So it seems that the GetCustomAttributes
extension methods are not returning the attributes on the pocos even in the sample. I am running the samples on VS 2012 (.net 4.5, targeting 3.5 in the sample project), IIS Express on a Win7 machine. Hope someone might be able to point me in the right direction for further investigation.