Java Code Examples for org.apache.solr.client.solrj.response.QueryResponse#toString()
The following examples show how to use
org.apache.solr.client.solrj.response.QueryResponse#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CaseController.java From skywalking with Apache License 2.0 | 6 votes |
@GetMapping("/healthcheck") public String healthcheck() throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(CommonParams.Q, "*:*"); params.set(CommonParams.OMIT_HEADER, true); HttpSolrClient client = getClient(); try { QueryResponse response = client.query(collection, params); if (response.getStatus() == 0) { return "Success"; } throw new Exception(response.toString()); } catch (Exception e) { throw e; } }
Example 2
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_Lower() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); for (String include : Arrays.asList(", include:lower", "")) { // same behavior final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", // exclude a single low value from our ranges "{ foo:{ type:range, field:"+INT_FIELD+" start:1, end:5, gap:1"+otherStr+include+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 4, buckets.size()); for (int i = 0; i < 4; i++) { int expectedVal = i+1; assertBucket("bucket#" + i, expectedVal, modelVals(expectedVal), subFacetLimit, buckets.get(i)); } assertBeforeAfterBetween(other, modelVals(0), modelVals(5), modelVals(1,4), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } } }
Example 3
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_Lower_Gap2() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); for (String include : Arrays.asList(", include:lower", "")) { // same behavior final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", "{ foo:{ type:range, field:"+INT_FIELD+" start:0, end:5, gap:2"+otherStr+include+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 3, buckets.size()); assertBucket("bucket#0", 0, modelVals(0,1), subFacetLimit, buckets.get(0)); assertBucket("bucket#1", 2, modelVals(2,3), subFacetLimit, buckets.get(1)); assertBucket("bucket#2", 4, modelVals(4,5), subFacetLimit, buckets.get(2)); assertBeforeAfterBetween(other, emptyVals(), emptyVals(), modelVals(0,5), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } } }
Example 4
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_Lower_Gap2_hardend() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); for (String include : Arrays.asList(", include:lower", "")) { // same behavior final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", "{ foo:{ type:range, field:"+INT_FIELD+" start:0, end:5, gap:2, hardend:true" + otherStr+include+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 3, buckets.size()); assertBucket("bucket#0", 0, modelVals(0,1), subFacetLimit, buckets.get(0)); assertBucket("bucket#1", 2, modelVals(2,3), subFacetLimit, buckets.get(1)); assertBucket("bucket#2", 4, modelVals(4), subFacetLimit, buckets.get(2)); assertBeforeAfterBetween(other, emptyVals(), modelVals(5), modelVals(0,4), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } } }
Example 5
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_Upper() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", // exclude a single high value from our ranges "{ foo:{ type:range, field:"+INT_FIELD+" start:0, end:4, gap:1, include:upper"+otherStr+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 4, buckets.size()); for (int i = 0; i < 4; i++) { assertBucket("bucket#" + i, i, modelVals(i+1), subFacetLimit, buckets.get(i)); } assertBeforeAfterBetween(other, modelVals(0), modelVals(5), modelVals(1,4), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } }
Example 6
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_Upper_Gap2() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", // exclude a single high value from our ranges "{ foo:{ type:range, field:"+INT_FIELD+" start:0, end:4, gap:2, include:upper"+otherStr+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 2, buckets.size()); assertBucket("bucket#0", 0, modelVals(1,2), subFacetLimit, buckets.get(0)); assertBucket("bucket#1", 2, modelVals(3,4), subFacetLimit, buckets.get(1)); assertBeforeAfterBetween(other, modelVals(0), modelVals(5), modelVals(1,4), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } }
Example 7
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_Edge() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", // exclude a single low/high value from our ranges "{ foo:{ type:range, field:"+INT_FIELD+" start:1, end:4, gap:1, include:edge"+otherStr+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 3, buckets.size()); assertBucket("bucket#0", 1, modelVals(1), subFacetLimit, buckets.get(0)); // middle bucket doesn't include lower or upper so it's empty assertBucket("bucket#1", 2, emptyVals(), subFacetLimit, buckets.get(1)); assertBucket("bucket#2", 3, modelVals(4), subFacetLimit, buckets.get(2)); assertBeforeAfterBetween(other, modelVals(0), modelVals(5), modelVals(1,4), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } }
Example 8
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_EdgeLower() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); for (String include : Arrays.asList(", include:'edge,lower'", ", include:[edge,lower]")) { // same final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", // exclude a single low/high value from our ranges "{ foo:{ type:range, field:"+INT_FIELD+" start:1, end:4, gap:1"+otherStr+include+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 3, buckets.size()); assertBucket("bucket#0", 1, modelVals(1), subFacetLimit, buckets.get(0)); assertBucket("bucket#1", 2, modelVals(2), subFacetLimit, buckets.get(1)); assertBucket("bucket#2", 3, modelVals(3,4), subFacetLimit, buckets.get(2)); assertBeforeAfterBetween(other, modelVals(0), modelVals(5), modelVals(1,4), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } } }
Example 9
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_EdgeUpper() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); for (String include : Arrays.asList(", include:'edge,upper'", ", include:[edge,upper]")) { // same final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", // exclude a single low/high value from our ranges "{ foo:{ type:range, field:"+INT_FIELD+" start:1, end:4, gap:1"+otherStr+include+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 3, buckets.size()); assertBucket("bucket#0", 1, modelVals(1,2), subFacetLimit, buckets.get(0)); assertBucket("bucket#1", 2, modelVals(3), subFacetLimit, buckets.get(1)); assertBucket("bucket#2", 3, modelVals(4), subFacetLimit, buckets.get(2)); assertBeforeAfterBetween(other, modelVals(0), modelVals(5), modelVals(1,4), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } } }
Example 10
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_EdgeLowerUpper() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); for (String include : Arrays.asList(", include:'edge,lower,upper'", ", include:[edge,lower,upper]")) { // same final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", // exclude a single low/high value from our ranges "{ foo:{ type:range, field:"+INT_FIELD+" start:1, end:4, gap:1"+otherStr+include+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 3, buckets.size()); assertBucket("bucket#0", 1, modelVals(1,2), subFacetLimit, buckets.get(0)); assertBucket("bucket#1", 2, modelVals(2,3), subFacetLimit, buckets.get(1)); assertBucket("bucket#2", 3, modelVals(3,4), subFacetLimit, buckets.get(2)); assertBeforeAfterBetween(other, modelVals(0), modelVals(5), modelVals(1,4), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } } }
Example 11
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_All() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); for (String include : Arrays.asList(", include:'edge,lower,upper,outer'", ", include:[edge,lower,upper,outer]", ", include:all")) { // same final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", // exclude a single low/high value from our ranges "{ foo:{ type:range, field:"+INT_FIELD+" start:1, end:4, gap:1"+otherStr+include+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 3, buckets.size()); assertBucket("bucket#0", 1, modelVals(1,2), subFacetLimit, buckets.get(0)); assertBucket("bucket#1", 2, modelVals(2,3), subFacetLimit, buckets.get(1)); assertBucket("bucket#2", 3, modelVals(3,4), subFacetLimit, buckets.get(2)); assertBeforeAfterBetween(other, modelVals(0,1), modelVals(4,5), modelVals(1,4), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } } }
Example 12
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testInclude_All_Gap2_hardend() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (EnumSet<FacetRangeOther> other : OTHERS) { final String otherStr = formatFacetRangeOther(other); for (String include : Arrays.asList(", include:'edge,lower,upper,outer'", ", include:[edge,lower,upper,outer]", ", include:all")) { // same final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", // exclude a single low/high value from our ranges "{ foo:{ type:range, field:"+INT_FIELD+" start:1, end:4, gap:2, hardend:true" + otherStr+include+subFacet+" } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 2, buckets.size()); assertBucket("bucket#0", 1, modelVals(1,3), subFacetLimit, buckets.get(0)); assertBucket("bucket#1", 3, modelVals(3,4), subFacetLimit, buckets.get(1)); assertBeforeAfterBetween(other, modelVals(0,1), modelVals(4,5), modelVals(1,4), subFacetLimit, foo); } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } } }
Example 13
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testRangeWithInterval() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (boolean incUpper : Arrays.asList(false, true)) { String incUpperStr = ",inclusive_to:"+incUpper; final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", "{ foo:{ type:range, field:" + INT_FIELD + " ranges:[{from:1, to:2"+ incUpperStr+ "}," + "{from:2, to:3"+ incUpperStr +"},{from:3, to:4"+ incUpperStr +"},{from:4, to:5"+ incUpperStr+"}]" + subFacet + " } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>) rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 4, buckets.size()); for (int i = 0; i < 4; i++) { String expectedVal = "[" + (i + 1) + "," + (i + 2) + (incUpper? "]": ")"); ModelRange modelVals = incUpper? modelVals(i+1, i+2) : modelVals(i+1); assertBucket("bucket#" + i, expectedVal, modelVals, subFacetLimit, buckets.get(i)); } } catch (AssertionError | RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } }
Example 14
Source File: RangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testRangeWithOldIntervalFormat() throws Exception { for (boolean doSubFacet : Arrays.asList(false, true)) { final Integer subFacetLimit = pickSubFacetLimit(doSubFacet); final CharSequence subFacet = makeSubFacet(subFacetLimit); for (boolean incUpper : Arrays.asList(false, true)) { String incUpperStr = incUpper? "]\"":")\""; final SolrQuery solrQuery = new SolrQuery ("q", "*:*", "rows", "0", "json.facet", "{ foo:{ type:range, field:" + INT_FIELD + " ranges:[{range:\"[1,2"+ incUpperStr+ "}," + "{range:\"[2,3"+ incUpperStr +"},{range:\"[3,4"+ incUpperStr +"},{range:\"[4,5"+ incUpperStr+"}]" + subFacet + " } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>) rsp.getResponse().get("facets")).get("foo"); @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals("num buckets", 4, buckets.size()); for (int i = 0; i < 4; i++) { String expectedVal = "[" + (i + 1) + "," + (i + 2) + (incUpper? "]": ")"); ModelRange modelVals = incUpper? modelVals(i+1, i+2) : modelVals(i+1); assertBucket("bucket#" + i, expectedVal, modelVals, subFacetLimit, buckets.get(i)); } } catch (AssertionError | RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } } }
Example 15
Source File: CurrencyRangeFacetCloudTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testJsonRangeFacetAsSubFacet() throws Exception { // limit=1, overrequest=1, with refinement enabled // filter out the first 5 docs (by id), which should ensure that 'x2' is the top bucket overall... // ...except in some rare sharding cases where it doesn't make it into the top 2 terms. // // So the filter also explicitly accepts all 'x2' docs -- ensuring we have enough matches containing that term for it // to be enough of a candidate in phase#1, but for many shard arrangements it won't be returned by all shards resulting // in refinement being neccessary to get the x_s:x2 sub-shard ranges from shard(s) where x_s:x2 is only tied for the // (shard local) top term count and would lose the (index order) tie breaker with x_s:x0 or x_s:x1 final String filter = "id_i1:["+VALUES.size()+" TO *] OR x_s:x2"; // the *facet* results should be the same regardless of wether we filter via fq, or using a domain filter on the top facet for (boolean use_domain : Arrays.asList(true, false)) { final String domain = use_domain ? "domain: { filter:'" + filter + "'}," : ""; final SolrQuery solrQuery = new SolrQuery("q", (use_domain ? "*:*" : filter), "rows", "0", "json.facet", "{ foo:{ type:terms, field:x_s, refine:true, limit:1, overrequest:1, " + domain + " facet: { bar:{ type:range, field:"+FIELD+", other:all, " + " start:'8,EUR', gap:'2,EUR', end:'22,EUR' }} } }"); final QueryResponse rsp = cluster.getSolrClient().query(solrQuery); try { // this top level result count sanity check that should vary based on how we are filtering our facets... assertEquals(use_domain ? 15 : 11, rsp.getResults().getNumFound()); @SuppressWarnings({"unchecked"}) final NamedList<Object> foo = ((NamedList<NamedList<Object>>)rsp.getResponse().get("facets")).get("foo"); // sanity check... // because of the facet limit, foo should only have 1 bucket // because of the fq, the val should be "x2" and the count=5 @SuppressWarnings({"unchecked"}) final List<NamedList<Object>> foo_buckets = (List<NamedList<Object>>) foo.get("buckets"); assertEquals(1, foo_buckets.size()); assertEquals("x2", foo_buckets.get(0).get("val")); assertEquals("foo bucket count", 5L, foo_buckets.get(0).get("count")); @SuppressWarnings({"unchecked"}) final NamedList<Object> bar = (NamedList<Object>)foo_buckets.get(0).get("bar"); // these are the 'x2' specific counts, based on our fq... assertEquals("before", 2L, ((NamedList)bar.get("before")).get("count")); assertEquals("after", 1L, ((NamedList)bar.get("after")).get("count")); assertEquals("between", 2L, ((NamedList)bar.get("between")).get("count")); @SuppressWarnings({"unchecked", "rawtypes"}) final List<NamedList> buckets = (List<NamedList>) bar.get("buckets"); assertEquals(7, buckets.size()); for (int i = 0; i < 7; i++) { @SuppressWarnings({"rawtypes"}) NamedList bucket = buckets.get(i); assertEquals((8 + (i * 2)) + ".00,EUR", bucket.get("val")); // 12,EUR & 15,EUR are the 2 values that align with x2 docs assertEquals("bucket #" + i, (i == 2 || i == 3) ? 1L : 0L, bucket.get("count")); } } catch (AssertionError|RuntimeException ae) { throw new AssertionError(solrQuery.toString() + " -> " + rsp.toString() + " ===> " + ae.getMessage(), ae); } } }
Example 16
Source File: DistribCursorPagingTest.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * <p> * Given a set of params, executes a cursor query using {@link CursorMarkParams#CURSOR_MARK_START} * and then continuously walks the results using {@link CursorMarkParams#CURSOR_MARK_START} as long * as a non-0 number of docs ar returned. This method records the the set of all id's * (must be positive ints) encountered and throws an assertion failure if any id is * encountered more then once, or if the set grows above maxSize * </p> * * <p> * Note that this method explicitly uses the "cloudClient" for executing the queries, * instead of relying on the test infrastructure to execute the queries redundently * against both the cloud client as well as a control client. This is because term stat * differences in a sharded setup can result in different scores for documents compared * to the control index -- which can affect the sorting in some cases and cause false * negatives in the response comparisons (even if we don't include "score" in the "fl") * </p> */ public SentinelIntSet assertFullWalkNoDups(int maxSize, SolrParams params) throws Exception { SentinelIntSet ids = new SentinelIntSet(maxSize, -1); String cursorMark = CURSOR_MARK_START; int docsOnThisPage = Integer.MAX_VALUE; while (0 < docsOnThisPage) { final SolrParams p = p(params, CURSOR_MARK_PARAM, cursorMark); QueryResponse rsp = cloudClient.query(p); String nextCursorMark = assertHashNextCursorMark(rsp); SolrDocumentList docs = extractDocList(rsp); docsOnThisPage = docs.size(); if (null != params.getInt(CommonParams.ROWS)) { int rows = params.getInt(CommonParams.ROWS); assertTrue("Too many docs on this page: " + rows + " < " + docsOnThisPage, docsOnThisPage <= rows); } if (0 == docsOnThisPage) { assertEquals("no more docs, but "+CURSOR_MARK_NEXT+" isn't same", cursorMark, nextCursorMark); } for (SolrDocument doc : docs) { int id = Integer.parseInt(doc.getFieldValue("id").toString()); if (ids.exists(id)) { String msg = "(" + p + ") walk already seen: " + id; try { queryAndCompareShards(params("distrib","false", "q","id:"+id)); } catch (AssertionError ae) { throw new AssertionError(msg + ", found shard inconsistency that would explain it...", ae); } rsp = cloudClient.query(params("q","id:"+id)); throw new AssertionError(msg + ", don't know why; q=id:"+id+" gives: " + rsp.toString()); } ids.put(id); assertFalse("id set bigger then max allowed ("+maxSize+"): " + ids.size(), maxSize < ids.size()); } cursorMark = nextCursorMark; } return ids; }