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 };
}
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;
}
Aggregations