示例#1
0
        private void AddCoresFromConfig(SolrServers solrServers) {
            if (solrServers == null) {
                return;
            }

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

        }
示例#2
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);
        }
 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);
 }
示例#4
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 Ping_And_Query_MultiCore()
 {
     var solrServers = new SolrServers {
         new SolrServerElement {
             Id = "main",
             Url = "http://localhost:8983/solr/core0",
             DocumentType = typeof(Entity).AssemblyQualifiedName,
         },
         new SolrServerElement {
             Id = "alt",
             Url = "http://localhost:8983/solr/core1",
             DocumentType = typeof(Entity2).AssemblyQualifiedName,
         }
     };
     kernel.Load(new SolrNetModule(solrServers));
     var solr1 = kernel.Get<ISolrOperations<Entity>>();
     solr1.Ping();
     Console.WriteLine("Query core 1: {0}", solr1.Query(SolrQuery.All).Count);
     var solr2 = kernel.Get<ISolrOperations<Entity2>>();
     solr2.Ping();
     Console.WriteLine("Query core 2: {0}", solr2.Query(SolrQuery.All).Count);
 }
示例#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.IsNotNull(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.IsNotNull(solr2);

            var r = solr2.Query("SomeField:Value");
            Assert.AreEqual(1, r.NumFound);
        }
示例#7
0
 /// <summary>
 /// Configures SolrNet in a Ninject kernel with multiple servers/cores
 /// </summary>
 /// <param name="solrServers"></param>
 public SolrNetModule(SolrServers solrServers)
 {
     AddCoresFromConfig(solrServers);
 }