NamedList values;
NamedList terms;
handler = core.getRequestHandler("/terms");
assertTrue("handler is null and it shouldn't be", handler != null);
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
values = rsp.getValues();
terms = (NamedList) ((NamedList) values.get("terms")).get("lowerfilt");
assertTrue("terms Size: " + terms.size() + " is not: " + 6, terms.size() == 6);
assertTrue("aa is null and it shouldn't be", terms.get("aa") != null);
assertTrue("aaa is null and it shouldn't be", terms.get("aaa") != null);
assertTrue("ab is null and it shouldn't be", terms.get("ab") != null);
assertTrue("abb is null and it shouldn't be", terms.get("abb") != null);
assertTrue("abc is null and it shouldn't be", terms.get("abc") != null);
assertTrue("a is null", terms.get("a") != null);
assertTrue("b is not null and it should be", terms.get("b") == null);
params.add(TermsParams.TERMS_UPPER_INCLUSIVE, "true");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
values = rsp.getValues();
terms = (NamedList) ((NamedList) values.get("terms")).get("lowerfilt");
assertTrue("terms Size: " + terms.size() + " is not: " + 7, terms.size() == 7);
assertTrue("aa is null and it shouldn't be", terms.get("aa") != null);
assertTrue("ab is null and it shouldn't be", terms.get("ab") != null);
assertTrue("aaa is null and it shouldn't be", terms.get("aaa") != null);
assertTrue("abb is null and it shouldn't be", terms.get("abb") != null);
assertTrue("abc is null and it shouldn't be", terms.get("abc") != null);
assertTrue("b is null and it shouldn't be", terms.get("b") != null);
assertTrue("a is null", terms.get("a") != null);
assertTrue("baa is not null", terms.get("baa") == null);
params = new ModifiableSolrParams();
params.add(TermsParams.TERMS, "true");
params.add(TermsParams.TERMS_FIELD, "lowerfilt");
params.add(TermsParams.TERMS_LOWER, "a");
params.add(TermsParams.TERMS_UPPER, "b");
params.add(TermsParams.TERMS_RAW, "true"); // this should have no effect on a text field
params.add(TermsParams.TERMS_LIMIT, String.valueOf(2));
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
values = rsp.getValues();
terms = (NamedList) ((NamedList) values.get("terms")).get("lowerfilt");
assertTrue("terms Size: " + terms.size() + " is not: " + 2, terms.size() == 2);
assertTrue("aa is null and it shouldn't be", terms.get("a") != null);
assertTrue("aaa is null and it shouldn't be", terms.get("aa") != null);
assertTrue("abb is not null", terms.get("abb") == null);
assertTrue("abc is not null", terms.get("abc") == null);
assertTrue("b is null and it shouldn't be", terms.get("b") == null);
assertTrue("baa is not null", terms.get("baa") == null);
params = new ModifiableSolrParams();
params.add(TermsParams.TERMS, "true");
params.add(TermsParams.TERMS_FIELD, "foo_i");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
values = rsp.getValues();
terms = (NamedList) ((NamedList) values.get("terms")).get("foo_i");
assertEquals(2,terms.get("1"));
params.add("terms.raw","true");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
values = rsp.getValues();
terms = (NamedList) ((NamedList) values.get("terms")).get("foo_i");
assertTrue(terms.get("1") == null);
// check something at the end of the index
params.set(TermsParams.TERMS_FIELD, "zzz_i");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
values = rsp.getValues();
terms = (NamedList) ((NamedList) values.get("terms")).get("zzz_i");
assertTrue(terms.size() == 0);