/**
   * A PrefixTree pruning optimization gone bad, applicable when optimize=true. See <a
   * href="https://issues.apache.org/jira/browse/LUCENE-4770">LUCENE-4770</a>.
   */
  @Test
  public void testBadPrefixTreePrune() throws Exception {

    trie = new QuadPrefixTree(ctx, 12);
    TermQueryPrefixTreeStrategy strategy = new TermQueryPrefixTreeStrategy(trie, "geo");
    Document doc = new Document();
    doc.add(new TextField("id", "1", Store.YES));

    Shape area = ctx.makeRectangle(-122.82, -122.78, 48.54, 48.56);

    Field[] fields = strategy.createIndexableFields(area, 0.025);
    for (Field field : fields) {
      doc.add(field);
    }
    addDocument(doc);

    Point upperleft = ctx.makePoint(-122.88, 48.54);
    Point lowerright = ctx.makePoint(-122.82, 48.62);

    Query query =
        strategy.makeQuery(
            new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(upperleft, lowerright)));

    commit();

    TopDocs search = indexSearcher.search(query, 10);
    ScoreDoc[] scoreDocs = search.scoreDocs;
    for (ScoreDoc scoreDoc : scoreDocs) {
      System.out.println(indexSearcher.doc(scoreDoc.doc));
    }

    assertEquals(1, search.totalHits);
  }
    @Override
    public void freeze() {
      super.freeze();
      // This is a bit hackish: we need to setup the spatial tree and strategies once the field name
      // is set, which
      // must be by the time freeze is called.
      SpatialPrefixTree prefixTree;
      if ("geohash".equals(tree)) {
        prefixTree =
            new GeohashPrefixTree(
                ShapeBuilder.SPATIAL_CONTEXT,
                getLevels(treeLevels, precisionInMeters, Defaults.GEOHASH_LEVELS, true));
      } else if ("legacyquadtree".equals(tree)) {
        prefixTree =
            new QuadPrefixTree(
                ShapeBuilder.SPATIAL_CONTEXT,
                getLevels(treeLevels, precisionInMeters, Defaults.QUADTREE_LEVELS, false));
      } else if ("quadtree".equals(tree)) {
        prefixTree =
            new PackedQuadPrefixTree(
                ShapeBuilder.SPATIAL_CONTEXT,
                getLevels(treeLevels, precisionInMeters, Defaults.QUADTREE_LEVELS, false));
      } else {
        throw new IllegalArgumentException("Unknown prefix tree type [" + tree + "]");
      }

      recursiveStrategy = new RecursivePrefixTreeStrategy(prefixTree, names().indexName());
      recursiveStrategy.setDistErrPct(distanceErrorPct());
      recursiveStrategy.setPruneLeafyBranches(false);
      termStrategy = new TermQueryPrefixTreeStrategy(prefixTree, names().indexName());
      termStrategy.setDistErrPct(distanceErrorPct());
      defaultStrategy = resolveStrategy(strategyName);
      defaultStrategy.setPointsOnly(pointsOnly);
    }