@Test
  public void testRangeFilterId() throws IOException {

    IndexReader reader = signedIndexReader;
    IndexSearcher search = newSearcher(reader);

    int medId = ((maxId - minId) / 2);

    String minIP = pad(minId);
    String maxIP = pad(maxId);
    String medIP = pad(medId);

    int numDocs = reader.numDocs();

    assertEquals("num of docs", numDocs, 1 + maxId - minId);

    ScoreDoc[] result;
    Query q = new TermQuery(new Term("body", "body"));

    // test id, bounded on both ends
    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", minIP, maxIP, T, T), numDocs)
            .scoreDocs;
    assertEquals("find all", numDocs, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", minIP, maxIP, T, F), numDocs)
            .scoreDocs;
    assertEquals("all but last", numDocs - 1, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", minIP, maxIP, F, T), numDocs)
            .scoreDocs;
    assertEquals("all but first", numDocs - 1, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", minIP, maxIP, F, F), numDocs)
            .scoreDocs;
    assertEquals("all but ends", numDocs - 2, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", medIP, maxIP, T, T), numDocs)
            .scoreDocs;
    assertEquals("med and up", 1 + maxId - medId, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", minIP, medIP, T, T), numDocs)
            .scoreDocs;
    assertEquals("up to med", 1 + medId - minId, result.length);

    // unbounded id

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", null, null, T, T), numDocs)
            .scoreDocs;
    assertEquals("find all", numDocs, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", minIP, null, T, F), numDocs)
            .scoreDocs;
    assertEquals("min and up", numDocs, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", null, maxIP, F, T), numDocs)
            .scoreDocs;
    assertEquals("max and down", numDocs, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", minIP, null, F, F), numDocs)
            .scoreDocs;
    assertEquals("not min, but up", numDocs - 1, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", null, maxIP, F, F), numDocs)
            .scoreDocs;
    assertEquals("not max, but down", numDocs - 1, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", medIP, maxIP, T, F), numDocs)
            .scoreDocs;
    assertEquals("med and up, not max", maxId - medId, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", minIP, medIP, F, T), numDocs)
            .scoreDocs;
    assertEquals("not min, up to med", medId - minId, result.length);

    // very small sets

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", minIP, minIP, F, F), numDocs)
            .scoreDocs;
    assertEquals("min,min,F,F", 0, result.length);
    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", medIP, medIP, F, F), numDocs)
            .scoreDocs;
    assertEquals("med,med,F,F", 0, result.length);
    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", maxIP, maxIP, F, F), numDocs)
            .scoreDocs;
    assertEquals("max,max,F,F", 0, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", minIP, minIP, T, T), numDocs)
            .scoreDocs;
    assertEquals("min,min,T,T", 1, result.length);
    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", null, minIP, F, T), numDocs)
            .scoreDocs;
    assertEquals("nul,min,F,T", 1, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", maxIP, maxIP, T, T), numDocs)
            .scoreDocs;
    assertEquals("max,max,T,T", 1, result.length);
    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", maxIP, null, T, F), numDocs)
            .scoreDocs;
    assertEquals("max,nul,T,T", 1, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("id", medIP, medIP, T, T), numDocs)
            .scoreDocs;
    assertEquals("med,med,T,T", 1, result.length);
  }
  @Test
  public void testFieldCacheRangeFilterRand() throws IOException {

    IndexReader reader = signedIndexReader;
    IndexSearcher search = newSearcher(reader);

    String minRP = pad(signedIndexDir.minR);
    String maxRP = pad(signedIndexDir.maxR);

    int numDocs = reader.numDocs();

    assertEquals("num of docs", numDocs, 1 + maxId - minId);

    ScoreDoc[] result;
    Query q = new TermQuery(new Term("body", "body"));

    // test extremes, bounded on both ends

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", minRP, maxRP, T, T), numDocs)
            .scoreDocs;
    assertEquals("find all", numDocs, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", minRP, maxRP, T, F), numDocs)
            .scoreDocs;
    assertEquals("all but biggest", numDocs - 1, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", minRP, maxRP, F, T), numDocs)
            .scoreDocs;
    assertEquals("all but smallest", numDocs - 1, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", minRP, maxRP, F, F), numDocs)
            .scoreDocs;
    assertEquals("all but extremes", numDocs - 2, result.length);

    // unbounded

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", minRP, null, T, F), numDocs)
            .scoreDocs;
    assertEquals("smallest and up", numDocs, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", null, maxRP, F, T), numDocs)
            .scoreDocs;
    assertEquals("biggest and down", numDocs, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", minRP, null, F, F), numDocs)
            .scoreDocs;
    assertEquals("not smallest, but up", numDocs - 1, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", null, maxRP, F, F), numDocs)
            .scoreDocs;
    assertEquals("not biggest, but down", numDocs - 1, result.length);

    // very small sets

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", minRP, minRP, F, F), numDocs)
            .scoreDocs;
    assertEquals("min,min,F,F", 0, result.length);
    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", maxRP, maxRP, F, F), numDocs)
            .scoreDocs;
    assertEquals("max,max,F,F", 0, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", minRP, minRP, T, T), numDocs)
            .scoreDocs;
    assertEquals("min,min,T,T", 1, result.length);
    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", null, minRP, F, T), numDocs)
            .scoreDocs;
    assertEquals("nul,min,F,T", 1, result.length);

    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", maxRP, maxRP, T, T), numDocs)
            .scoreDocs;
    assertEquals("max,max,T,T", 1, result.length);
    result =
        search.search(q, FieldCacheRangeFilter.newStringRange("rand", maxRP, null, T, F), numDocs)
            .scoreDocs;
    assertEquals("max,nul,T,T", 1, result.length);
  }