Search in sources :

Example 6 with CellIterator

use of org.apache.lucene.spatial.prefix.tree.CellIterator 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)6 CellIterator (org.apache.lucene.spatial.prefix.tree.CellIterator)6 ArrayList (java.util.ArrayList)3 Point (org.locationtech.spatial4j.shape.Point)3 Shape (org.locationtech.spatial4j.shape.Shape)3 TermInSetQuery (org.apache.lucene.search.TermInSetQuery)2 BytesRef (org.apache.lucene.util.BytesRef)2 Repeat (com.carrotsearch.randomizedtesting.annotations.Repeat)1 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DocIdSet (org.apache.lucene.search.DocIdSet)1 Facets (org.apache.lucene.spatial.prefix.NumberRangePrefixTreeStrategy.Facets)1 LegacyCell (org.apache.lucene.spatial.prefix.tree.LegacyCell)1 NumberRangePrefixTree (org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree)1 UnitNRShape (org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape)1 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)1 SpatialOperation (org.apache.lucene.spatial.query.SpatialOperation)1 UnsupportedSpatialOperation (org.apache.lucene.spatial.query.UnsupportedSpatialOperation)1