Java Code Examples for org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree

The following examples show how to use org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lucene-solr   Source File: SpatialDocMaker.java    License: Apache License 2.0 6 votes vote down vote up
protected RecursivePrefixTreeStrategy makeRPTStrategy(String spatialField, Config config,
                                                      Map<String, String> configMap, SpatialContext ctx) {
  //A factory for the prefix tree grid
  SpatialPrefixTree grid = SpatialPrefixTreeFactory.makeSPT(configMap, null, ctx);

  RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, spatialField);
  strategy.setPointsOnly(config.get("spatial.docPointsOnly", false));
  final boolean pruneLeafyBranches = config.get("spatial.pruneLeafyBranches", true);
  if (grid instanceof PackedQuadPrefixTree) {
    ((PackedQuadPrefixTree) grid).setPruneLeafyBranches(pruneLeafyBranches);
    strategy.setPruneLeafyBranches(false);//always leave it to packed grid, even though it isn't the same
  } else {
    strategy.setPruneLeafyBranches(pruneLeafyBranches);
  }

  int prefixGridScanLevel = config.get("query.spatial.prefixGridScanLevel", -4);
  if (prefixGridScanLevel < 0)
    prefixGridScanLevel = grid.getMaxLevels() + prefixGridScanLevel;
  strategy.setPrefixGridScanLevel(prefixGridScanLevel);

  double distErrPct = config.get("spatial.distErrPct", .025);//doc & query; a default
  strategy.setDistErrPct(distErrPct);
  return strategy;
}
 
Example 2
public void setupGrid(int maxLevels) throws IOException {
  if (randomBoolean())
    setupQuadGrid(maxLevels, randomBoolean());
  else
    setupGeohashGrid(maxLevels);
  setupCtx2D(ctx);

  // set prune independently on strategy & grid randomly; should work
  ((RecursivePrefixTreeStrategy)strategy).setPruneLeafyBranches(randomBoolean());
  if (this.grid instanceof PackedQuadPrefixTree) {
    ((PackedQuadPrefixTree) this.grid).setPruneLeafyBranches(randomBoolean());
  }

  if (maxLevels == -1 && rarely()) {
    ((PrefixTreeStrategy) strategy).setPointsOnly(true);
  }

  log.info("Strategy: " +  strategy.toString()); // logOk
}
 
Example 3
private void setupQuadGrid(int maxLevels, boolean packedQuadPrefixTree) {
  //non-geospatial makes this test a little easier (in gridSnap), and using boundary values 2^X raises
  // the prospect of edge conditions we want to test, plus makes for simpler numbers (no decimals).
  SpatialContextFactory factory = new SpatialContextFactory();
  factory.geo = false;
  factory.worldBounds = new RectangleImpl(0, 256, -128, 128, null);
  this.ctx = factory.newSpatialContext();
  //A fairly shallow grid, and default 2.5% distErrPct
  if (maxLevels == -1)
    maxLevels = randomIntBetween(1, 8);//max 64k cells (4^8), also 256*256
  if (packedQuadPrefixTree) {
    this.grid = new PackedQuadPrefixTree(ctx, maxLevels);
  } else {
    this.grid = new QuadPrefixTree(ctx, maxLevels);
  }
  this.strategy = newRPT();
}
 
Example 4
@Override
protected RecursivePrefixTreeStrategy newPrefixTreeStrategy(String fieldName) {
  RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, fieldName);
  if (prefixGridScanLevel != null)
    strategy.setPrefixGridScanLevel(prefixGridScanLevel);
  if (grid instanceof PackedQuadPrefixTree) {
    // This grid has a (usually) better prune leafy branch implementation
    ((PackedQuadPrefixTree) grid).setPruneLeafyBranches(true);
    strategy.setPruneLeafyBranches(false);
  }
  return strategy;
}