Skip to content

Commit

Permalink
added sort order
Browse files Browse the repository at this point in the history
git-svn-id: http://solrnet.googlecode.com/svn/trunk@50 66c3f25c-543c-0410-ae2e-6f2ca0bd8c61
  • Loading branch information
mausch committed Oct 21, 2007
1 parent 665daf5 commit 9abd4b2
Show file tree
Hide file tree
Showing 25 changed files with 230 additions and 74 deletions.
32 changes: 16 additions & 16 deletions HttpWebAdapters/Impl/HttpWebResponseAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public CookieCollection Cookies {
public string ContentEncoding {
get {
try {
return ((HttpWebResponse)response).ContentEncoding;
return ((HttpWebResponse) response).ContentEncoding;
} catch (InvalidCastException) {
return ((WebResponseStub)response).ContentEncoding;
}
return ((WebResponseStub) response).ContentEncoding;
}
}
}

Expand All @@ -85,9 +85,9 @@ public string ContentEncoding {
public string CharacterSet {
get {
try {
return ((HttpWebResponse)response).CharacterSet;
return ((HttpWebResponse) response).CharacterSet;
} catch (InvalidCastException) {
return ((WebResponseStub)response).CharacterSet;
return ((WebResponseStub) response).CharacterSet;
}
}
}
Expand All @@ -104,9 +104,9 @@ public string CharacterSet {
public string Server {
get {
try {
return ((HttpWebResponse)response).Server;
return ((HttpWebResponse) response).Server;
} catch (InvalidCastException) {
return ((WebResponseStub)response).Server;
return ((WebResponseStub) response).Server;
}
}
}
Expand All @@ -123,9 +123,9 @@ public string Server {
public DateTime LastModified {
get {
try {
return ((HttpWebResponse)response).LastModified;
return ((HttpWebResponse) response).LastModified;
} catch (InvalidCastException) {
return ((WebResponseStub)response).LastModified;
return ((WebResponseStub) response).LastModified;
}
}
}
Expand All @@ -142,7 +142,7 @@ public DateTime LastModified {
public HttpStatusCode StatusCode {
get {
try {
return ((HttpWebResponse)response).StatusCode;
return ((HttpWebResponse) response).StatusCode;
} catch (InvalidCastException) {
return ((WebResponseStub) response).StatusCode;
}
Expand All @@ -161,9 +161,9 @@ public HttpStatusCode StatusCode {
public string StatusDescription {
get {
try {
return ((HttpWebResponse)response).StatusDescription;
return ((HttpWebResponse) response).StatusDescription;
} catch (InvalidCastException) {
return ((WebResponseStub)response).StatusDescription;
return ((WebResponseStub) response).StatusDescription;
}
}
}
Expand All @@ -180,9 +180,9 @@ public string StatusDescription {
public Version ProtocolVersion {
get {
try {
return ((HttpWebResponse)response).ProtocolVersion;
return ((HttpWebResponse) response).ProtocolVersion;
} catch (InvalidCastException) {
return ((WebResponseStub)response).ProtocolVersion;
return ((WebResponseStub) response).ProtocolVersion;
}
}
}
Expand All @@ -199,9 +199,9 @@ public Version ProtocolVersion {
public string Method {
get {
try {
return ((HttpWebResponse)response).Method;
return ((HttpWebResponse) response).Method;
} catch (InvalidCastException) {
return ((WebResponseStub)response).Method;
return ((WebResponseStub) response).Method;
}
}
}
Expand Down
48 changes: 48 additions & 0 deletions SolrNet.DSL.Tests/DSLTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,54 @@ public void QueryByExample() {
mocks.VerifyAll();
}

[Test]
public void OrderBy() {
MockRepository mocks = new MockRepository();
ISolrConnection conn = mocks.CreateMock<ISolrConnection>();
IDictionary<string, string> query = new Dictionary<string, string>();
query["q"] = "Id:123456";
query["sort"] = "id";
Expect.Call(conn.Get("/select", query)).Repeat.Once().Return(response);
mocks.ReplayAll();
Solr.Connection = conn;
TestDocumentWithId doc = new TestDocumentWithId();
doc.Id = 123456;
Solr.Query<TestDocumentWithId>().ByExample(doc).OrderBy("id").Run();
mocks.VerifyAll();
}

[Test]
public void OrderByAscDesc() {
MockRepository mocks = new MockRepository();
ISolrConnection conn = mocks.CreateMock<ISolrConnection>();
IDictionary<string, string> query = new Dictionary<string, string>();
query["q"] = "Id:123456";
query["sort"] = "id ASC";
Expect.Call(conn.Get("/select", query)).Repeat.Once().Return(response);
mocks.ReplayAll();
Solr.Connection = conn;
TestDocumentWithId doc = new TestDocumentWithId();
doc.Id = 123456;
Solr.Query<TestDocumentWithId>().ByExample(doc).OrderBy("id", Order.ASC).Run();
mocks.VerifyAll();
}

[Test]
public void OrderByAscDescMultiple() {
MockRepository mocks = new MockRepository();
ISolrConnection conn = mocks.CreateMock<ISolrConnection>();
IDictionary<string, string> query = new Dictionary<string, string>();
query["q"] = "Id:123456";
query["sort"] = "id ASC,name DESC";
Expect.Call(conn.Get("/select", query)).Repeat.Once().Return(response);
mocks.ReplayAll();
Solr.Connection = conn;
TestDocumentWithId doc = new TestDocumentWithId();
doc.Id = 123456;
Solr.Query<TestDocumentWithId>().ByExample(doc).OrderBy("id", Order.ASC).OrderBy("name", Order.DESC).Run();
mocks.VerifyAll();
}

[Test]
public void DeleteByQuery() {
const string q = "id:123456";
Expand Down
25 changes: 3 additions & 22 deletions SolrNet.DSL/DSLQuery.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
using System;
using SolrNet;

namespace SolrNet.DSL {
public class DSLQuery<T> : IDSLQuery<T> where T : ISolrDocument, new() {
protected ISolrConnection connection;
protected ISolrQuery<T> query;

public DSLQuery(ISolrConnection connection) {
this.connection = connection;
}
public class DSLQuery<T> : DSLRun<T>, IDSLQuery<T> where T : ISolrDocument, new() {
public DSLQuery(ISolrConnection connection) : base(connection) {}

public DSLQuery(ISolrConnection connection, ISolrQuery<T> query) {
this.connection = connection;
this.query = query;
}
public DSLQuery(ISolrConnection connection, ISolrQuery<T> query) : base(connection, query) {}

public IDSLQueryRange<T> ByRange<RT>(string fieldName, RT from, RT to) {
return new DSLQueryRange<T, RT>(connection, query, fieldName, from, to);
}

public virtual ISolrQueryResults<T> Run() {
return new SolrQueryExecuter<T>(connection, query).Execute();
}

public virtual ISolrQueryResults<T> Run(int start, int rows) {
return new SolrQueryExecuter<T>(connection, query).Execute(start, rows);
}

public IDSLQueryBy<T> By(string fieldName) {
return new DSLQueryBy<T>(fieldName, connection, query);
}
Expand Down
48 changes: 48 additions & 0 deletions SolrNet.DSL/DSLRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections.Generic;

namespace SolrNet.DSL {
public class DSLRun<T> : IDSLRun<T> where T : ISolrDocument, new() {
private ICollection<SortOrder> order = new List<SortOrder>();
protected ISolrConnection connection;
protected ISolrQuery<T> query;

public DSLRun(ISolrConnection connection) {
this.connection = connection;
}

public DSLRun(ISolrConnection connection, ISolrQuery<T> query) {
this.connection = connection;
this.query = query;
}

public DSLRun(ISolrConnection connection, ISolrQuery<T> query, ICollection<SortOrder> order) {
this.connection = connection;
this.query = query;
this.order = order;
}

public ISolrQueryResults<T> Run() {
ISolrQueryExecuter<T> exe = new SolrQueryExecuter<T>(connection, query);
exe.OrderBy = order;
return exe.Execute();
}

public ISolrQueryResults<T> Run(int start, int rows) {
ISolrQueryExecuter<T> exe = new SolrQueryExecuter<T>(connection, query);
exe.OrderBy = order;
return exe.Execute(start, rows);
}

public IDSLRun<T> OrderBy(string fieldName) {
List<SortOrder> newOrder = new List<SortOrder>(order);
newOrder.Add(new SortOrder(fieldName));
return new DSLRun<T>(connection, query, newOrder);
}

public IDSLRun<T> OrderBy(string fieldName, Order o) {
List<SortOrder> newOrder = new List<SortOrder>(order);
newOrder.Add(new SortOrder(fieldName, o));
return new DSLRun<T>(connection, query, newOrder);
}
}
}
4 changes: 1 addition & 3 deletions SolrNet.DSL/IDSLQuery.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
namespace SolrNet.DSL {
public interface IDSLQuery<T> where T : ISolrDocument, new() {
public interface IDSLQuery<T> : IDSLRun<T> where T : ISolrDocument, new() {
IDSLQueryRange<T> ByRange<RT>(string fieldName, RT from, RT to);
ISolrQueryResults<T> Run();
ISolrQueryResults<T> Run(int start, int rows);
IDSLQueryBy<T> By(string fieldName);
IDSLQuery<T> ByExample(T doc);
}
Expand Down
8 changes: 8 additions & 0 deletions SolrNet.DSL/IDSLRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SolrNet.DSL {
public interface IDSLRun<T> where T : ISolrDocument, new() {
ISolrQueryResults<T> Run();
ISolrQueryResults<T> Run(int start, int rows);
IDSLRun<T> OrderBy(string fieldName);
IDSLRun<T> OrderBy(string fieldName, Order o);
}
}
2 changes: 0 additions & 2 deletions SolrNet.DSL/Solr.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using Rhino.Commons;
using SolrNet;

namespace SolrNet.DSL {
/// <summary>
Expand Down Expand Up @@ -79,6 +78,5 @@ public static void Optimize(bool waitFlush, bool waitSearcher) {
cmd.WaitSearcher = waitSearcher;
cmd.Execute(Connection);
}

}
}
2 changes: 2 additions & 0 deletions SolrNet.DSL/SolrNet.DSL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
<Compile Include="DSLQueryBetween.cs" />
<Compile Include="DSLQueryBy.cs" />
<Compile Include="DSLQueryRange.cs" />
<Compile Include="DSLRun.cs" />
<Compile Include="IDSLQuery.cs" />
<Compile Include="IDSLQueryBetween.cs" />
<Compile Include="IDSLQueryBy.cs" />
<Compile Include="IDSLQueryRange.cs" />
<Compile Include="IDSLRun.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Solr.cs" />
<Compile Include="Utils\ILocalData.cs" />
Expand Down
16 changes: 7 additions & 9 deletions SolrNet.Tests/AddCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ public decimal caca {
}
}

public class TestDocWithCollections: ISolrDocument {
public class TestDocWithCollections : ISolrDocument {
[SolrField]
public ICollection<string> coll {
get {
return new string[] {"one", "two"};
}
get { return new string[] {"one", "two"}; }
}
}

Expand Down Expand Up @@ -52,15 +50,15 @@ public void SupportsDocumentWithStringCollection() {
ISolrConnection conn = mocks.CreateMock<ISolrConnection>();
conn.Post("/update", "<add><doc><field name=\"coll\"><arr><str>one</str><str>two</str></arr></field></doc></add>");
LastCall.Repeat.Once().Do(new Writer(delegate(string ignored, string s) {
Console.WriteLine(s);
return null;
}));
Console.WriteLine(s);
return null;
}));
SetupResult.For(conn.ServerURL).Return("");
mocks.ReplayAll();
TestDocWithCollections[] docs = new TestDocWithCollections[] { new TestDocWithCollections() };
TestDocWithCollections[] docs = new TestDocWithCollections[] {new TestDocWithCollections()};
AddCommand<TestDocWithCollections> cmd = new AddCommand<TestDocWithCollections>(docs);
cmd.Execute(conn);
mocks.VerifyAll();
mocks.VerifyAll();
}

[Test]
Expand Down
2 changes: 0 additions & 2 deletions SolrNet.Tests/SolrConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using HttpWebAdapters;
using NUnit.Framework;
using Rhino.Mocks;
Expand Down
6 changes: 2 additions & 4 deletions SolrNet.Tests/SolrDocumentSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ public decimal Dd {
}
}

public class TestDocWithCollections: ISolrDocument {
public class TestDocWithCollections : ISolrDocument {
[SolrField]
public ICollection<string> coll {
get {
return new string[] {"one", "two"};
}
get { return new string[] {"one", "two"}; }
}
}

Expand Down
Loading

0 comments on commit 9abd4b2

Please sign in to comment.