Java Code Examples for org.apache.solr.client.solrj.SolrQuery#toString()

The following examples show how to use org.apache.solr.client.solrj.SolrQuery#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: AbstractAlfrescoDistributedIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void assertCountAndColocation(SolrQuery query, int count) throws Exception
{
    List<SolrClient> clients = getShardedClients();
    int shardHit = 0;
    int totalCount = 0;
    for (SolrClient client : clients)
    {
        QueryResponse response = client.query(query);
        int hits = (int) response.getResults().getNumFound();
        totalCount += hits;
        if (hits > 0) {
            shardHit++;
        }
    }

    if (totalCount != count) {
        throw new Exception(totalCount + " docs found for query: " + query.toString() + " expecting " + count);
    }

    if (shardHit > 1) {
        throw new Exception(shardHit + " shards found data for query: " + query.toString() + " expecting 1");
    }
}
 
Example 2
Source File: AbstractAlfrescoDistributedIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void assertShardSequence(int shard, SolrQuery query, int count) throws Exception
{
    List<SolrClient> clients = getShardedClients();
    int totalCount;
    SolrClient client = clients.get(shard);

    QueryResponse response = client.query(query);
    totalCount = (int) response.getResults().getNumFound();

    if(totalCount != count) {
        throw new Exception(totalCount+" docs found for query: "+query.toString()+" expecting "+count);
    }
}
 
Example 3
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 4
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 5
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 6
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 7
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 8
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 9
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 10
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 11
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 12
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 13
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 14
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 15
Source File: RangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 16
Source File: CurrencyRangeFacetCloudTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@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 17
Source File: DistributedDebugComponentTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("resource") // Cannot close client in this loop!
public void testRandom() throws Exception {
  final int NUM_ITERS = atLeast(50);

  for (int i = 0; i < NUM_ITERS; i++) {
    final SolrClient client = random().nextBoolean() ? collection1 : collection2;

    SolrQuery q = new SolrQuery();
    q.set("distrib", "true");
    q.setFields("id", "text");

    boolean shard1Results = random().nextBoolean();
    boolean shard2Results = random().nextBoolean();

    String qs = "_query_with_no_results_";
    if (shard1Results) {
      qs += " OR batman";
    }
    if (shard2Results) {
      qs += " OR superman";
    }
    q.setQuery(qs);

    Set<String> shards = new HashSet<String>(Arrays.asList(shard1, shard2));
    if (random().nextBoolean()) {
      shards.remove(shard1);
    } else if (random().nextBoolean()) {
      shards.remove(shard2);
    }
    q.set("shards", String.join(",", shards));


    List<String> debug = new ArrayList<String>(10);

    boolean all = false;
    final boolean timing = random().nextBoolean();
    final boolean query = random().nextBoolean();
    final boolean results = random().nextBoolean();
    final boolean track = random().nextBoolean();

    if (timing) { debug.add("timing"); }
    if (query) { debug.add("query"); }
    if (results) { debug.add("results"); }
    if (track) { debug.add("track"); }
    if (debug.isEmpty()) {
      debug.add("true");
      all = true;
    }
    q.set("debug", debug.toArray(new String[debug.size()]));

    QueryResponse r = client.query(q);
    try {
      assertDebug(r, all || track, "track");
      assertDebug(r, all || query, "rawquerystring");
      assertDebug(r, all || query, "querystring");
      assertDebug(r, all || query, "parsedquery");
      assertDebug(r, all || query, "parsedquery_toString");
      assertDebug(r, all || query, "QParser");
      assertDebug(r, all || results, "explain");
      assertDebug(r, all || timing, "timing");
    } catch (AssertionError e) {
      throw new AssertionError(q.toString() + ": " + e.getMessage(), e);
    }
  }
}