示例#1
0
        public void AddWithBoost()
        {
            var connection = new MSolrConnection();
            connection.post += (url, content) => {
                Assert.AreEqual("/update", url);
                Assert.AreEqual("<add><doc boost=\"2.1\" /></add>", content);
                return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
            };
            var docSerializer = new SolrDocumentSerializer<TestDocumentWithoutUniqueKey>(new AttributesMappingManager(), new DefaultFieldSerializer());
            var headerParser = new MSolrHeaderResponseParser();
            headerParser.parse = headerParser.parse.Return(null);
            var ops = new SolrBasicServer<TestDocumentWithoutUniqueKey>(connection, null, docSerializer, null, headerParser, null, null, null);
            ops.AddWithBoost(new[] { new KeyValuePair<TestDocumentWithoutUniqueKey, double?>(new TestDocumentWithoutUniqueKey(), 2.1), }, null);

            Assert.AreEqual(1, connection.post.Calls);
        }
示例#2
0
 public void AddWithParameters() {
     var xml = EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
     var connection = new MSolrConnection();
     connection.post += (url, content) => {
         Assert.AreEqual("/update", url);
         Assert.AreEqual("<add commitWithin=\"4343\" overwrite=\"false\"><doc /></add>", content);
         return xml;
     };
     var docSerializer = new SolrDocumentSerializer<TestDocumentWithoutUniqueKey>(new AttributesMappingManager(), new DefaultFieldSerializer());
     var headerParser = new MSolrHeaderResponseParser();
     headerParser.parse = headerParser.parse.Return(null);
     var ops = new SolrBasicServer<TestDocumentWithoutUniqueKey>(connection, null, docSerializer, null, headerParser, null, null, null);
     var parameters = new AddParameters { CommitWithin = 4343, Overwrite = false };
     ops.AddWithBoost(new[] { new KeyValuePair<TestDocumentWithoutUniqueKey, double?>(new TestDocumentWithoutUniqueKey(), null), }, parameters);
     Assert.AreEqual(1, connection.post.Calls);
 }
示例#3
0
        public void Add() {
            var xml = EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
            var connection = new MSolrConnection();
            connection.post = connection.post
                .Expect(1)
                .Args("/update", "<add><doc /></add>")
                .Return(xml);

            var headerParser = new MSolrHeaderResponseParser();
            headerParser.parse = headerParser.parse.Return(null);

            var docSerializer = new SolrDocumentSerializer<TestDocumentWithoutUniqueKey>(new AttributesMappingManager(), new DefaultFieldSerializer());
            var ops = new SolrBasicServer<TestDocumentWithoutUniqueKey>(connection, null, docSerializer, null, headerParser, null, null, null);
            ops.AddWithBoost(new[] {
                new KeyValuePair<TestDocumentWithoutUniqueKey, double?>(new TestDocumentWithoutUniqueKey(), null),
            }, null);
            connection.post.Verify();
        }
示例#4
0
        public void OptimizeWithWaitOptions()
        {
            var connection = new MSolrConnection();
            connection.post += (url, content) => {
                Assert.AreEqual("/update", url);
                Assert.AreEqual("<optimize waitSearcher=\"true\" waitFlush=\"true\" />", content);
                return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
            };

            var headerParser = new MSolrHeaderResponseParser();
            headerParser.parse += _ => null;

            var ops = new SolrBasicServer<TestDocumentWithoutUniqueKey>(connection, null, null, null, headerParser, null, null, null);
            ops.Optimize(new CommitOptions { WaitFlush = true, WaitSearcher = true });
        }
示例#5
0
        public void Optimize()
        {
            var connection = new MSolrConnection();
            connection.post += (url, content) => {
                Assert.AreEqual("/update", url);
                Assert.AreEqual("<optimize />", content);
                return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
            };

            var headerParser = new MSolrHeaderResponseParser();
            headerParser.parse += _ => null;

            var ops = new SolrBasicServer<TestDocumentWithoutUniqueKey>(connection, null, null, null, headerParser, null, null, null);
            ops.Optimize(null);
            Assert.AreEqual(1, connection.post.Calls);
        }
示例#6
0
 public void DeleteByQuery()
 {
     var connection = new MSolrConnection();
     connection.post += (url, content) => {
         Assert.AreEqual("/update", url);
         Assert.AreEqual("<delete><query>id:123</query></delete>", content);
         return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
     };
     var headerParser = new MSolrHeaderResponseParser();
     headerParser.parse += _ => null;
     var querySerializer = new MSolrQuerySerializer();
     querySerializer.serialize += _ => "id:123";
     var ops = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, null, null, null, headerParser, querySerializer, null, null);
     ops.Delete(null, new SolrQuery("id:123"));
     Assert.AreEqual(1, connection.post.Calls);
 }
示例#7
0
 public void DeleteByMultipleId()
 {
     var connection = new MSolrConnection();
     connection.post += (url, content) => {
         Assert.AreEqual("/update", url);
         Assert.AreEqual("<delete><id>0</id><id>0</id></delete>", content);
         return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
     };
     var headerParser = new MSolrHeaderResponseParser();
     headerParser.parse += _ => null;
     var basic = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, null, null, null, headerParser, null, null, null);
     var ops = new SolrServer<TestDocumentWithUniqueKey>(basic, new AttributesMappingManager(), null);
     ops.Delete(new[] {
         new TestDocumentWithUniqueKey(),
         new TestDocumentWithUniqueKey(),
     });
     Assert.AreEqual(1, connection.post.Calls);
 }
示例#8
0
 public void CommitWithOptions2_WaitSearcher()
 {
     var connection = new MSolrConnection();
     connection.post += (url, content) => {
         Assert.AreEqual("/update", url);
         Assert.AreEqual("<commit waitSearcher=\"false\" />", content);
         return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
     };
     var headerParser = new MSolrHeaderResponseParser();
     headerParser.parse &= x => x.Stub();
     var ops = new SolrBasicServer<TestDocumentWithoutUniqueKey>(connection, null, null, null, headerParser, null, null, null);
     ops.Commit(new CommitOptions { WaitSearcher = false });
     Assert.AreEqual(1, connection.post.Calls);
 }
示例#9
0
        public void CommitWithOptions()
        {
            var connection = new MSolrConnection();
            connection.post += (url, content) => {
                Assert.AreEqual("/update", url);
                Assert.AreEqual("<commit />", content);
                return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
            };
            connection.post &= x => x.Expect(1);

            var headerParser = new MSolrHeaderResponseParser();
            headerParser.parse += _ => null;

            var ops = new SolrBasicServer<TestDocumentWithoutUniqueKey>(connection, null, null, null, headerParser, null, null, null);
            ops.Commit(new CommitOptions());
            connection.post.Verify();
        }
示例#10
0
        public void Commit()
        {
            var connection = new MSolrConnection();
            connection.post &= x => x.Args("/update", "<commit />")
                                     .Return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"))
                                     .Expect(1);

            var headerParser = new MSolrHeaderResponseParser();
            headerParser.parse = headerParser.parse.Return(null);

            var ops = new SolrBasicServer<TestDocumentWithoutUniqueKey>(connection, null, null, null, headerParser, null, null, null);
            ops.Commit(null);
            connection.post.Verify();
        }