Skip to content

Commit

Permalink
Added more tests and small code changes to ExpandComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Bernstein committed Jan 29, 2014
1 parent 2fb7278 commit a4b688a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
Expand Up @@ -113,14 +113,9 @@ public void process(ResponseBuilder rb) throws IOException {

String field = params.get("expand.field");
String sortParam = params.get("expand.sort");
String limitString = params.get("expand.limit");
int limit = params.getInt("expand.rows", 5);

Sort sort = null;
int limit = 5;

if(limitString != null) {
limit = Integer.parseInt(limitString);
}

if(sortParam != null) {
sort = QueryParsing.parseSort(sortParam, rb.req);
Expand All @@ -133,8 +128,8 @@ public void process(ResponseBuilder rb) throws IOException {
FixedBitSet collapsedSet = new FixedBitSet(reader.maxDoc());

if(ids != null) {
List<String> idArr = StrUtils.splitSmart(ids, ",", true);
for(int i=0; i<idArr.size(); i++) {
List<String> idArr = StrUtils.splitSmart(ids, ",", true);
for(int i=0; i<idArr.size(); i++) {
int id = Integer.parseInt(idArr.get(i));
int ordValue = values.getOrd(id);
collapsedSet.set(id);
Expand Down
Expand Up @@ -67,6 +67,14 @@ public void testExpand() throws Exception {
assertU(adoc(doc5));
assertU(commit());

String[] doc6 = {"id","7", "term_s", "YYYY", "group_s", "group1", "test_ti", "1", "test_tl", "100000", "test_tf", "2000"};
assertU(adoc(doc6));
assertU(commit());
String[] doc7 = {"id","8", "term_s","YYYY", "group_s", "group2", "test_ti", "2", "test_tl", "100000", "test_tf", "200"};
assertU(adoc(doc7));
assertU(commit());



//First basic test case.
ModifiableSolrParams params = new ModifiableSolrParams();
Expand All @@ -81,8 +89,53 @@ public void testExpand() throws Exception {
"/response/result/doc[1]/float[@name='id'][.='2.0']",
"/response/result/doc[2]/float[@name='id'][.='6.0']",
"/response/lst[@name='expanded']/result[@name='group1']/doc[1]/float[@name='id'][.='1.0']",
"/response/lst[@name='expanded']/result[@name='group2']/doc[1]/float[@name='id'][.='5.0']"
"/response/lst[@name='expanded']/result[@name='group1']/doc[2]/float[@name='id'][.='7.0']",
"/response/lst[@name='expanded']/result[@name='group2']/doc[1]/float[@name='id'][.='5.0']",
"/response/lst[@name='expanded']/result[@name='group2']/doc[2]/float[@name='id'][.='8.0']"
);

//Test expand.sort
params = new ModifiableSolrParams();
params.add("q", "*:*");
params.add("fq", "{!collapse field=group_s}");
params.add("defType", "edismax");
params.add("bf", "field(test_ti)");
params.add("expand", "true");
params.add("expand.field", "group_s");
params.add("expand.sort", "test_tl desc");
assertQ(req(params), "*[count(/response/result/doc)=2]",
"*[count(/response/lst[@name='expanded']/result)=2]",
"/response/result/doc[1]/float[@name='id'][.='2.0']",
"/response/result/doc[2]/float[@name='id'][.='6.0']",
"/response/lst[@name='expanded']/result[@name='group1']/doc[1]/float[@name='id'][.='7.0']",
"/response/lst[@name='expanded']/result[@name='group1']/doc[2]/float[@name='id'][.='1.0']",
"/response/lst[@name='expanded']/result[@name='group2']/doc[1]/float[@name='id'][.='8.0']",
"/response/lst[@name='expanded']/result[@name='group2']/doc[2]/float[@name='id'][.='5.0']"
);


//Test expand.rows

params = new ModifiableSolrParams();
params.add("q", "*:*");
params.add("fq", "{!collapse field=group_s}");
params.add("defType", "edismax");
params.add("bf", "field(test_ti)");
params.add("expand", "true");
params.add("expand.field", "group_s");
params.add("expand.sort", "test_tl desc");
params.add("expand.rows", "1");
assertQ(req(params), "*[count(/response/result/doc)=2]",
"*[count(/response/lst[@name='expanded']/result)=2]",
"*[count(/response/lst[@name='expanded']/result[@name='group1']/doc)=1]",
"*[count(/response/lst[@name='expanded']/result[@name='group2']/doc)=1]",
"/response/result/doc[1]/float[@name='id'][.='2.0']",
"/response/result/doc[2]/float[@name='id'][.='6.0']",
"/response/lst[@name='expanded']/result[@name='group1']/doc[1]/float[@name='id'][.='7.0']",
"/response/lst[@name='expanded']/result[@name='group2']/doc[1]/float[@name='id'][.='8.0']"
);



}
}

0 comments on commit a4b688a

Please sign in to comment.