本文整理汇总了C#中SolrNet.Impl.SolrConnection.Get方法的典型用法代码示例。如果您正苦于以下问题:C# SolrConnection.Get方法的具体用法?C# SolrConnection.Get怎么用?C# SolrConnection.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SolrNet.Impl.SolrConnection
的用法示例。
在下文中一共展示了SolrConnection.Get方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Cache
public void Cache()
{
var conn = new SolrConnection(solrURL, new HttpWebRequestFactory());
var response1 = conn.Get("/select/", new Dictionary<string, string> {
{"q", "*:*"},
});
var response2 = conn.Get("/select/", new Dictionary<string, string> {
{"q", "*:*"},
});
}
示例2: ActualConnection
public void ActualConnection() {
var conn = new SolrConnection(solrURL) { HttpWebRequestFactory = new HttpWebRequestFactory() };
var p = new Dictionary<string, string>();
p["version"] = "2.1";
p["indent"] = "on";
p["q"] = "+video +price:[* TO 400]";
Console.WriteLine(conn.Get("/select/", p));
}
示例3: ActualInvalidFieldException
public void ActualInvalidFieldException()
{
var conn = new SolrConnection(solrURL, new HttpWebRequestFactory());
var p = new Dictionary<string, string>();
p["version"] = "2.1";
p["indent"] = "on";
p["q"] = "idq:123";
Console.WriteLine(conn.Get("/select/", p));
}
示例4: ActualConnectionWithException
public void ActualConnectionWithException() {
var conn = new SolrConnection(solrURL);
var p = new Dictionary<string, string>();
p["version"] = "2.1";
p["indent"] = "on";
p["q"] = "idq:123";
try {
conn.Get("/select/", p);
Assert.Fail("Should have thrown");
} catch (SolrConnectionException e) {
Console.WriteLine(e);
Console.WriteLine(e.Url);
}
}
示例5: Get
public void Get() {
var response = new Mocks.HttpWebResponse {
dispose = () => {},
headers = () => new WebHeaderCollection(),
getResponseStream = () => new MemoryStream(Encoding.UTF8.GetBytes("hello world")),
};
var request = new Mocks.HttpWebRequest {
getResponse = () => response
};
var reqFactory = new Mocks.HttpWebRequestFactory {
create = _ => request
};
var conn = new SolrConnection("https://pepe") {
HttpWebRequestFactory = reqFactory,
};
var r = conn.Get("", new Dictionary<string, string>());
Assert.AreEqual("hello world", r);
}
示例6: Cache_mocked
public void Cache_mocked()
{
var conn = new SolrConnection(solrURL, new HttpWebRequestFactory());
var cache = MockRepository.GenerateMock<ISolrCache>();
cache.Expect(x => x["http://localhost:8983/solr/select/?q=*:*"])
.Repeat.Once()
.Return(null);
cache.Expect(x => x.Add(null)).Repeat.Once();
conn.Cache = cache;
var response1 = conn.Get("/select/", new Dictionary<string, string> {
{"q", "*:*"},
});
var response2 = conn.Get("/select/", new Dictionary<string, string> {
{"q", "*:*"},
});
}
示例7: UndefinedFieldQueryError_ShouldThrow
public void UndefinedFieldQueryError_ShouldThrow()
{
var mocks = new MockRepository();
var reqFactory = mocks.StrictMock<IHttpWebRequestFactory>();
var request = mocks.DynamicMock<IHttpWebRequest>();
With.Mocks(mocks).Expecting(delegate {
Expect.Call(reqFactory.Create(new UriBuilder().Uri))
.IgnoreArguments()
.Repeat.Once()
.Return(request);
var r = new WebResponseStub {StatusCode = HttpStatusCode.BadRequest};
Expect.Call(request.GetResponse())
.Repeat.Once()
.Throw(new WebException("(400) Bad Request", new ApplicationException(), WebExceptionStatus.ProtocolError, r));
}).Verify(delegate {
var conn = new SolrConnection("https://pepe", reqFactory);
conn.Get("", new Dictionary<string, string>());
});
}
示例8: InvalidHostGet_ShouldThrowException
public void InvalidHostGet_ShouldThrowException()
{
var mocks = new MockRepository();
var reqFactory = mocks.StrictMock<IHttpWebRequestFactory>();
var request = mocks.DynamicMock<IHttpWebRequest>();
With.Mocks(mocks).Expecting(delegate {
Expect.Call(reqFactory.Create(new UriBuilder().Uri))
.IgnoreArguments()
.Repeat.Once()
.Return(request);
Expect.Call(request.GetResponse())
.Repeat.Once()
.Throw(new WebException());
}).Verify(delegate {
var conn = new SolrConnection("http://lalala:12345", reqFactory);
conn.Get("", new Dictionary<string, string>());
});
}
示例9: GetWithNullParameters_ShouldAcceptNull
public void GetWithNullParameters_ShouldAcceptNull()
{
var mocks = new MockRepository();
var reqFactory = mocks.StrictMock<IHttpWebRequestFactory>();
var request = mocks.DynamicMock<IHttpWebRequest>();
var response = mocks.DynamicMock<IHttpWebResponse>();
With.Mocks(mocks).Expecting(delegate {
Expect.Call(reqFactory.Create(new UriBuilder().Uri))
.IgnoreArguments()
.Repeat.Once()
.Return(request);
Expect.Call(response.Headers)
.Repeat.Any()
.Return(new WebHeaderCollection());
Expect.Call(request.GetResponse())
.Repeat.Once()
.Return(response);
Expect.Call(response.GetResponseStream())
.Repeat.Once()
.Return(new MemoryStream());
}).Verify(delegate {
var conn = new SolrConnection("https://pepe", reqFactory);
conn.Get("", new Dictionary<string, string>());
});
}
示例10: Get_Compressed_Gzip
public void Get_Compressed_Gzip()
{
var mocks = new MockRepository();
var reqFactory = mocks.StrictMock<IHttpWebRequestFactory>();
var request = mocks.DynamicMock<IHttpWebRequest>();
var response = mocks.DynamicMock<IHttpWebResponse>();
With.Mocks(mocks).Expecting(delegate
{
Expect.Call(reqFactory.Create(new UriBuilder().Uri))
.IgnoreArguments()
.Repeat.Once()
.Return(request);
Expect.Call(request.Headers)
.Repeat.Any()
.Return(new WebHeaderCollection());
Expect.Call(response.ContentEncoding)
.Repeat.Any()
.Return("gzip");
Expect.Call(response.Headers)
.Repeat.Any()
.Return(new WebHeaderCollection());
Expect.Call(request.GetResponse())
.Repeat.Once()
.Return(response);
Expect.Call(response.GetResponseStream())
.Repeat.Once()
.Return(CompressionUtils.GzipCompressStream("Testing compression"));
}).Verify(delegate {
var conn = new SolrConnection("http://localhost") { HttpWebRequestFactory = reqFactory };
Assert.AreEqual("Testing compression", conn.Get("", new Dictionary<string, string>()));
});
}
示例11: InvalidHostGet_ShouldThrowException
public void InvalidHostGet_ShouldThrowException() {
var reqFactory = new Mocks.HttpWebRequestFactory {
create = _ => new Mocks.HttpWebRequest {
getResponse = () => { throw new WebException();}
}
};
var conn = new SolrConnection("http://lalala:12345") { HttpWebRequestFactory = reqFactory };
conn.Get("", new Dictionary<string, string>());
}
示例12: Cache
public void Cache() {
var conn = new SolrConnection(solrURL);
conn.Get("/select/", new Dictionary<string, string> {
{"q", "*:*"},
});
conn.Get("/select/", new Dictionary<string, string> {
{"q", "*:*"},
});
}
示例13: Cache_mocked
public void Cache_mocked() {
var cache = new Mocks.MSolrCache();
cache.get += url => {
Assert.AreEqual("http://localhost:8983/solr/select/?q=*:*&version=2.2", url);
return new SolrCacheEntity(url, "", "");
};
cache.add &= x => x.Stub();
var response = new Mocks.HttpWebResponse {
dispose = () => {},
headers = () => new WebHeaderCollection {
{HttpResponseHeader.ETag, "123"},
},
getResponseStream = () => new MemoryStream(),
};
var getResponseCalls = 0;
var conn = new SolrConnection(solrURL) {
Cache = cache,
HttpWebRequestFactory = new Mocks.HttpWebRequestFactory {
create = _ => new Mocks.HttpWebRequest {
getResponse = () => {
getResponseCalls++;
if (getResponseCalls == 1)
return response;
throw new Exception();
},
Headers = new WebHeaderCollection(),
},
}
};
conn.Get("/select/", new Dictionary<string, string> {
{"q", "*:*"},
});
conn.Get("/select/", new Dictionary<string, string> {
{"q", "*:*"},
});
}
示例14: CacheMaxAge_ShouldCallGetResponseWhenExpired
public void CacheMaxAge_ShouldCallGetResponseWhenExpired()
{
var cache = new Mocks.MSolrCache();
cache.get += url =>
{
Assert.AreEqual("http://localhost:8983/solr/select/?q=*:*&version=2.2", url);
return new SolrCacheEntity(url, "", "", new DateTime(2013, 5, 12, 12, 30, 30));
};
cache.add &= x => x.Stub();
var response = new Mocks.HttpWebResponse
{
dispose = () => { },
headers = () => new WebHeaderCollection(),
getResponseStream = () => new MemoryStream(),
};
var getResponseCalls = 0;
var conn = new SolrConnection(solrURL)
{
Cache = cache,
HttpWebRequestFactory = new Mocks.HttpWebRequestFactory
{
create = _ => new Mocks.HttpWebRequest
{
getResponse = () =>
{
getResponseCalls++;
return response;
},
Headers = new WebHeaderCollection(),
},
}
};
SystemTime.UtcNow = () => new DateTime(2013, 5, 12, 12, 30, 29);
conn.Get("/select/", new Dictionary<string, string> {
{"q", "*:*"},
});
Assert.AreEqual(getResponseCalls, 0, "Should not call getResponse when valid expiration");
SystemTime.UtcNow = () => new DateTime(2013, 5, 12, 12, 30, 35);
conn.Get("/select/", new Dictionary<string, string> {
{"q", "*:*"},
});
Assert.AreEqual(getResponseCalls, 1, "Should call getResponse if the cache entry is expired");
}