Search in sources :

Example 11 with Cell

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

the class PrefixTreeStrategy method createIndexableFields.

public Field[] createIndexableFields(Shape shape, int detailLevel) {
    //TODO re-use TokenStream LUCENE-5776: Subclass Field, put cell iterator there, override tokenStream()
    Iterator<Cell> cells = createCellIteratorToIndex(shape, detailLevel, null);
    CellToBytesRefIterator cellToBytesRefIterator = newCellToBytesRefIterator();
    cellToBytesRefIterator.reset(cells);
    BytesRefIteratorTokenStream tokenStream = new BytesRefIteratorTokenStream();
    tokenStream.setBytesRefIterator(cellToBytesRefIterator);
    Field field = new Field(getFieldName(), tokenStream, FIELD_TYPE);
    return new Field[] { field };
}
Also used : Field(org.apache.lucene.document.Field) Cell(org.apache.lucene.spatial.prefix.tree.Cell)

Example 12 with Cell

use of org.apache.lucene.spatial.prefix.tree.Cell 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)12 CellIterator (org.apache.lucene.spatial.prefix.tree.CellIterator)6 Point (org.locationtech.spatial4j.shape.Point)4 ArrayList (java.util.ArrayList)3 Shape (org.locationtech.spatial4j.shape.Shape)3 IOException (java.io.IOException)2 DocIdSet (org.apache.lucene.search.DocIdSet)2 TermInSetQuery (org.apache.lucene.search.TermInSetQuery)2 LegacyCell (org.apache.lucene.spatial.prefix.tree.LegacyCell)2 UnitNRShape (org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape)2 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)2 BytesRef (org.apache.lucene.util.BytesRef)2 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)2 Repeat (com.carrotsearch.randomizedtesting.annotations.Repeat)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Field (org.apache.lucene.document.Field)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Term (org.apache.lucene.index.Term)1