public void Ping_And_Query_SingleCore()
        {
            var solrServers = new SolrServers {
                new SolrServerElement {
                    Id           = "default",
                    Url          = "http://localhost:8983/solr/core0",
                    DocumentType = typeof(Entity).AssemblyQualifiedName,
                }
            };

            kernel.Load(new SolrNetModule(solrServers));
            var solr = kernel.Get <ISolrOperations <Entity> >();

            solr.Ping();
            Console.WriteLine(solr.Query(SolrQuery.All).Count);
        }
Beispiel #2
0
        private void AddCoresFromConfig(SolrServers solrServers, IUnityContainer container)
        {
            if (solrServers == null)
            {
                return;
            }

            var cores =
                from server in solrServers.Cast <SolrServerElement>()
                select GetCoreFrom(server);

            foreach (var core in cores)
            {
                RegisterCore(core, container);
            }
        }
Beispiel #3
0
        public SolrNetRegistry(SolrServers solrServers)
        {
            For <IReadOnlyMappingManager>().Use <MemoizingMappingManager>()
            .Ctor <IReadOnlyMappingManager>("mapper").Is(new AttributesMappingManager());
            For(typeof(ISolrDocumentActivator <>)).Use(typeof(SolrDocumentActivator <>));
            For(typeof(ISolrQueryExecuter <>)).Use(typeof(SolrQueryExecuter <>));
            For <ISolrDocumentPropertyVisitor>().Use <DefaultDocumentVisitor>();
            For <IMappingValidator>().Use <MappingValidator>();

            RegisterParsers();
            RegisterValidationRules();
            RegisterSerializers();
            RegisterOperations();

            AddCoresFromConfig(solrServers);
        }
        public IUnityContainer ConfigureContainer(SolrServers solrServers, IUnityContainer container)
        {
            container.RegisterType <IReadOnlyMappingManager, MemoizingMappingManager>(new InjectionConstructor(new ResolvedParameter(typeof(AttributesMappingManager))));
            container.RegisterType(typeof(ISolrDocumentActivator <>), typeof(SolrDocumentActivator <>));
            container.RegisterType(typeof(ISolrQueryExecuter <>), typeof(SolrQueryExecuter <>));
            container.RegisterType <ISolrDocumentPropertyVisitor, DefaultDocumentVisitor>();
            container.RegisterType <IMappingValidator, MappingValidator>();

            RegisterParsers(container);
            RegisterValidationRules(container);
            RegisterSerializers(container);

            AddCoresFromConfig(solrServers, container);

            return(container);
        }
Beispiel #5
0
        public void ResolveSolrOperations()
        {
            //var kernel = new StandardKernel();

            var solrServers = new SolrServers {
                new SolrServerElement {
                    Id           = "default",
                    Url          = "http://localhost:8983/solr",
                    DocumentType = typeof(Entity).AssemblyQualifiedName,
                }
            };

            kernel.Load(new SolrNetModule(solrServers));
            var solr = kernel.Get <ISolrOperations <Entity> >();

            Assert.IsNotNull(solr);
        }
Beispiel #6
0
        public void MultiCore_Rebind_IConnection()
        {
            var solrServers = new SolrServers {
                new SolrServerElement {
                    Id           = "core-0",
                    Url          = "http://*****:*****@"<?xml version=""1.0"" encoding=""UTF-8""?>
<response>
<lst name=""responseHeader""><int name=""status"">0</int><int name=""QTime"">0</int><lst name=""params""><str name=""q"">id:123456</str><str name=""?""/><str name=""version"">2.2</str></lst></lst><result name=""response"" numFound=""1"" start=""0""><doc></doc></result>
</response>
";

            var solr1 = kernel.Get <ISolrOperations <Entity> >("core-0");

            Assert.NotNull(solr1);

            Assert.Throws <SolrConnectionException>(() => solr1.Query("SomeField:Value"));

            MSolrConnection conn = new MSolrConnection();

            conn.get &= x => x.Return(Response);
            kernel.Rebind <ISolrConnection>().ToConstant(conn).WithMetadata("CoreId", "core-0");
            kernel.Rebind <ISolrConnection>().ToConstant(conn).WithMetadata("CoreId", "core-1");

            var solr2 = kernel.Get <ISolrOperations <Entity> >("core-1");

            Assert.NotNull(solr2);

            var r = solr2.Query("SomeField:Value");

            Assert.Equal(1, r.NumFound);
        }
Beispiel #7
0
        public void Same_document_type_different_core_url()
        {
            var cores = new SolrServers {
                new SolrServerElement {
                    Id           = "core1",
                    DocumentType = typeof(Entity).AssemblyQualifiedName,
                    Url          = "http://localhost:8983/solr/entity1",
                },
                new SolrServerElement {
                    Id           = "core2",
                    DocumentType = typeof(Entity).AssemblyQualifiedName,
                    Url          = "http://localhost:8983/solr/entity2",
                }
            };

            container = new UnityContainer();
            new SolrNetContainerConfiguration().ConfigureContainer(cores, container);
            var core1 = container.Resolve <ISolrOperations <Entity> >("core1");
            var core2 = container.Resolve <ISolrOperations <Entity> >("core2");
        }
Beispiel #8
0
        private void AddCoresFromConfig(SolrServers solrServers)
        {
            if (solrServers == null)
            {
                return;
            }

            var cores = new List <SolrCore>();

            foreach (SolrServerElement server in solrServers)
            {
                var solrCore = GetCoreFrom(server);
                cores.Add(solrCore);
            }

            foreach (var core in cores)
            {
                RegisterCore(core);
            }
        }
Beispiel #9
0
        public void ResolveSolrReadOnlyOperations()
        {
            // Arrange
            var builder = new ContainerBuilder();
            var cores   = new SolrServers {
                new SolrServerElement {
                    Id           = "entity1",
                    DocumentType = typeof(Entity1).AssemblyQualifiedName,
                    Url          = "http://localhost:8983/solr/coreEntity1",
                },
            };

            builder.RegisterModule(new SolrNetModule(cores));
            var container = builder.Build();

            // Act
            var solrReadOnlyOperations = container.Resolve <ISolrReadOnlyOperations <Entity1> >();

            // Assert
            Assert.True(solrReadOnlyOperations is SolrServer <Entity1>);
        }
        public void DictionaryDocument_add()
        {
            var cores = new SolrServers {
                new SolrServerElement {
                    Id           = "entity1dict",
                    DocumentType = typeof(Dictionary <string, object>).AssemblyQualifiedName,
                    Url          = "http://localhost:8983/solr/core1",
                }
            };

            Container.Configure(c => c.AddRegistry(SolrNetRegistry.Create(cores)));

            var solr = Container.GetInstance <ISolrOperations <Dictionary <string, object> > >();

            solr.Add(new Dictionary <string, object>
            {
                { "id", "ababa" },
                { "manu", "who knows" },
                { "popularity", 55 },
                { "timestamp", DateTime.UtcNow },
            });
        }
Beispiel #11
0
        public void MultiCore_SameClassBinding()
        {
            var solrServers = new SolrServers {
                new SolrServerElement {
                    Id           = "core-0",
                    Url          = "http://localhost:8983/solr/core0",
                    DocumentType = typeof(Entity).AssemblyQualifiedName,
                },
                new SolrServerElement {
                    Id           = "core-1",
                    Url          = "http://localhost:8983/solr/core1",
                    DocumentType = typeof(Entity).AssemblyQualifiedName,
                }
            };

            kernel.Load(new SolrNetModule(solrServers));
            var solr1 = kernel.Get <ISolrOperations <Entity> >("core-0");

            Assert.IsNotNull(solr1);
            var solr2 = kernel.Get <ISolrOperations <Entity> >("core-1");

            Assert.IsNotNull(solr2);
        }
 public void DictionaryDocument_and_multi_core()
 {
     var cores = new SolrServers {
         new SolrServerElement {
             Id           = "default",
             DocumentType = typeof(Entity).AssemblyQualifiedName,
             Url          = "http://localhost:8983/solr/entity1",
         },
         new SolrServerElement {
             Id           = "entity1dict",
             DocumentType = typeof(Dictionary <string, object>).AssemblyQualifiedName,
             Url          = "http://localhost:8983/solr/entity1",
         },
         new SolrServerElement {
             Id           = "another",
             DocumentType = typeof(Entity2).AssemblyQualifiedName,
             Url          = "http://localhost:8983/solr/entity2",
         },
     };
     var container = new Container(c => c.IncludeRegistry(SolrNetRegistry.Create(cores)));
     var solr1     = container.GetInstance <ISolrOperations <Entity> >();
     var solr2     = container.GetInstance <ISolrOperations <Entity2> >();
     var solrDict  = container.GetInstance <ISolrOperations <Dictionary <string, object> > >();
 }
Beispiel #13
0
 /// <summary>
 ///   Register multi-core server
 /// </summary>
 /// <param name = "solrServers"></param>
 public SolrNetModule(SolrServers solrServers)
 {
     this.solrServers = solrServers;
 }
Beispiel #14
0
 /// <summary>
 /// Configures SolrNet in a Ninject kernel with multiple servers/cores
 /// </summary>
 /// <param name="solrServers"></param>
 public SolrNetModule(SolrServers solrServers)
 {
     AddCoresFromConfig(solrServers);
 }