forked from SolrNet/SolrNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
569 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Linq; | ||
using MbUnit.Framework; | ||
using SolrNet.Impl; | ||
using SolrNet.Impl.DocumentPropertyVisitors; | ||
using SolrNet.Impl.FieldParsers; | ||
using SolrNet.Impl.ResponseParsers; | ||
using SolrNet.Mapping; | ||
using SolrNet.Tests.Utils; | ||
|
||
namespace SolrNet.Tests | ||
{ | ||
[TestFixture] | ||
public class CollapseExpandResponseParserTests | ||
{ | ||
[Test] | ||
public void Parse() | ||
{ | ||
var mapper = new AttributesMappingManager(); | ||
var parser = new CollapseExpandResponseParser<Doc>(new SolrDocumentResponseParser<Doc>(mapper, new DefaultDocumentVisitor(mapper, new DefaultFieldParser()), new SolrDocumentActivator<Doc>())); | ||
var xml = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.collapseWithoutExpandResponse.xml"); | ||
var results = new SolrQueryResults<Doc>(); | ||
parser.Parse(xml, results); | ||
Assert.IsNull(results.CollapseExpand); | ||
} | ||
|
||
[Test] | ||
public void Parse2() | ||
{ | ||
var mapper = new AttributesMappingManager(); | ||
var parser = new CollapseExpandResponseParser<Doc>(new SolrDocumentResponseParser<Doc>(mapper, new DefaultDocumentVisitor(mapper, new DefaultFieldParser()), new SolrDocumentActivator<Doc>())); | ||
var xml = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.collapseWithExpandResponse.xml"); | ||
var results = new SolrQueryResults<Doc>(); | ||
parser.Parse(xml, results); | ||
Assert.IsNotNull(results.CollapseExpand); | ||
Assert.AreEqual(4, results.CollapseExpand.Groups.Count); | ||
|
||
var group = results.CollapseExpand.Groups.ElementAt(0); | ||
Assert.AreEqual(group.Documents.Count, 2); | ||
Assert.AreEqual(group.GroupValue, "First"); | ||
Assert.AreEqual(group.NumFound, 2); | ||
} | ||
|
||
class Doc {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<response> | ||
<result name="response" numFound="4" start="0"> | ||
<doc> | ||
<str name="fieldKey">First</str> | ||
<str name="fieldValue">First value</str> | ||
</doc> | ||
<doc> | ||
<str name="fieldKey">Second</str> | ||
<str name="fieldValue">Second value</str> | ||
</doc> | ||
<doc> | ||
<str name="fieldKey">Third</str> | ||
<str name="fieldValue">Third value</str> | ||
</doc> | ||
<doc> | ||
<str name="fieldKey">Fourth</str> | ||
<str name="fieldValue">Fourth value</str> | ||
</doc> | ||
</result> | ||
<lst name="expanded"> | ||
<result name="First" numFound="2" start="0"> | ||
<doc> | ||
<str name="fieldKey">First</str> | ||
<str name="fieldValue">First value</str> | ||
</doc> | ||
<doc> | ||
<str name="fieldKey">First</str> | ||
<str name="fieldValue">First value 2</str> | ||
</doc> | ||
</result> | ||
<result name="Second" numFound="1" start="0"> | ||
<doc> | ||
<str name="fieldKey">Second</str> | ||
<str name="fieldValue">Second value</str> | ||
</doc> | ||
</result> | ||
<result name="Third" numFound="1" start="0"> | ||
<doc> | ||
<str name="fieldKey">Third</str> | ||
<str name="fieldValue">Third value</str> | ||
</doc> | ||
</result> | ||
<result name="Fourth" numFound="1" start="0"> | ||
<doc> | ||
<str name="fieldKey">Fourth</str> | ||
<str name="fieldValue">Fourth value</str> | ||
</doc> | ||
</result> | ||
</lst> | ||
</response> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<response> | ||
<result name="response" numFound="4" start="0"> | ||
<doc> | ||
<str name="fieldKey">First</str> | ||
<str name="fieldValue">First value</str> | ||
</doc> | ||
<doc> | ||
<str name="fieldKey">Second</str> | ||
<str name="fieldValue">Second value</str> | ||
</doc> | ||
<doc> | ||
<str name="fieldKey">Third</str> | ||
<str name="fieldValue">Third value</str> | ||
</doc> | ||
<doc> | ||
<str name="fieldKey">Fourth</str> | ||
<str name="fieldValue">Fourth value</str> | ||
</doc> | ||
</result> | ||
</response> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace SolrNet | ||
{ | ||
/// <summary> | ||
/// Collapse/expand results model | ||
/// </summary> | ||
public class CollapseExpandResults<T> | ||
{ | ||
private readonly ICollection<Group<T>> groups; | ||
|
||
/// <summary> | ||
/// Grouped documents | ||
/// </summary> | ||
public ICollection<Group<T>> Groups | ||
{ | ||
get { return groups; } | ||
} | ||
|
||
/// <summary> | ||
/// Constructor for CollapseExpandResults | ||
/// </summary> | ||
public CollapseExpandResults(ICollection<Group<T>> groups) | ||
{ | ||
this.groups = groups; | ||
} | ||
} | ||
} |
Oops, something went wrong.