Search in sources :

Example 1 with LegacyCell

use of org.apache.lucene.spatial.prefix.tree.LegacyCell in project lucene-solr by apache.

the class RecursivePrefixTreeStrategy method recursiveTraverseAndPrune.

/** Returns true if cell was added as a leaf. If it wasn't it recursively descends. */
private boolean recursiveTraverseAndPrune(Cell cell, Shape shape, int detailLevel, List<Cell> result) {
    // calling cell.getNextLevelCells(). This is only true for LegacyCell.
    if (!(cell instanceof LegacyCell))
        throw new IllegalStateException("pruneLeafyBranches must be disabled for use with grid " + grid);
    if (cell.getLevel() == detailLevel) {
        //FYI might already be a leaf
        cell.setLeaf();
    }
    if (cell.isLeaf()) {
        result.add(cell);
        return true;
    }
    if (cell.getLevel() != 0)
        result.add(cell);
    int leaves = 0;
    CellIterator subCells = cell.getNextLevelCells(shape);
    while (subCells.hasNext()) {
        Cell subCell = subCells.next();
        if (recursiveTraverseAndPrune(subCell, shape, detailLevel, result))
            leaves++;
    }
    //can we prune?
    if (leaves == ((LegacyCell) cell).getSubCellsSize() && cell.getLevel() != 0) {
        //remove the leaves
        do {
            //remove last
            result.remove(result.size() - 1);
        } while (--leaves > 0);
        //add cell as the leaf
        cell.setLeaf();
        return true;
    }
    return false;
}
Also used : LegacyCell(org.apache.lucene.spatial.prefix.tree.LegacyCell) CellIterator(org.apache.lucene.spatial.prefix.tree.CellIterator) Cell(org.apache.lucene.spatial.prefix.tree.Cell) LegacyCell(org.apache.lucene.spatial.prefix.tree.LegacyCell)

Aggregations

Cell (org.apache.lucene.spatial.prefix.tree.Cell)1 CellIterator (org.apache.lucene.spatial.prefix.tree.CellIterator)1 LegacyCell (org.apache.lucene.spatial.prefix.tree.LegacyCell)1