|
Initialization
Initializing the library
Setting up the libraryOnce you have created your document class, you have to initialize the library in order to operate against the Solr instance. This is usually done once at application startup: Startup.Init<Product>("http://localhost:8983/solr");Then you ask the service locator for the SolrNet service instance which allows you to issue any supported operation: var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
solr.Delete(SolrQuery.All);
solr.Add(p);
solr.Commit();
var products = solr.Query(new SolrQueryByRange<decimal>("price", 10m, 100m));Castle WindsorAlternatively, if your app uses Castle Windsor you can set up SolrNet using the included facility: container.AddFacility("solr", new SolrNetFacility("http://localhost:8983/solr"));Or using Windsor's xml config: <castle>
<facilities>
<facility id="solr" type="Castle.Facilities.SolrNetIntegration.SolrNetFacility, SolrNet">
<solrURL>http://localhost:8983/solr</solrURL>
</facility>
</facilities>
</castle>NinjectIf you're using Ninject, you can use the Ninject module: kernel.Load(new SolrNetModule("http://localhost:8983/solr"));StructureMapIf you are using StructureMap, you can use the StructureMap module (StructureMap.SolrNetIntegration): ObjectFactory.Initialize(
x => x.AddRegistry(
new SolrNetRegistry("http://localhost:8893/solr")
)
);Autofac(SolrNet 0.4.0) For Autofac var builder = new ContainerBuilder();
builder.RegisterModule(new SolrNetModule("http://localhost:8983/solr"));
var container = builder.Build();Unity(SolrNet 0.4.0) For Unity: var solrServers = new SolrServers {
new SolrServerElement {
Id = "test",
Url = "htp://localhost:8893",
DocumentType = typeof (Entity).AssemblyQualifiedName,
}
};
container = new UnityContainer();
new SolrNetContainerConfiguration().ConfigureContainer(solrServers, container);Multi-core mappingIf you need to map multiple Solr cores/instances, see Accessing multiple Solr cores/instances |