org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy Java Examples

The following examples show how to use org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy. 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 File: SpatialDocMaker.java    From lucene-solr with 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
Source File: QueryEqualsHashCodeTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testEqualsHashCode() {

  switch (random().nextInt(4)) {//0-3
    case 0: predicate = SpatialOperation.Contains; break;
    case 1: predicate = SpatialOperation.IsWithin; break;

    default: predicate = SpatialOperation.Intersects; break;
  }
  final SpatialPrefixTree gridQuad = new QuadPrefixTree(ctx,10);
  final SpatialPrefixTree gridGeohash = new GeohashPrefixTree(ctx,10);

  Collection<SpatialStrategy> strategies = new ArrayList<>();
  RecursivePrefixTreeStrategy recursive_geohash = new RecursivePrefixTreeStrategy(gridGeohash, "recursive_geohash");
  strategies.add(recursive_geohash);
  strategies.add(new TermQueryPrefixTreeStrategy(gridQuad, "termquery_quad"));
  strategies.add(PointVectorStrategy.newInstance(ctx, "pointvector"));
  strategies.add(BBoxStrategy.newInstance(ctx, "bbox"));
  final SerializedDVStrategy serialized = new SerializedDVStrategy(ctx, "serialized");
  strategies.add(serialized);
  strategies.add(new CompositeSpatialStrategy("composite", recursive_geohash, serialized));
  for (SpatialStrategy strategy : strategies) {
    testEqualsHashcode(strategy);
  }
}
 
Example #3
Source File: LuceneIndex.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Function<String, ? extends SpatialStrategy> createSpatialStrategyMapper(Map<String, String> parameters) {
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	SpatialContext geoContext = SpatialContextFactory.makeSpatialContext(parameters, classLoader);
	final SpatialPrefixTree spt = SpatialPrefixTreeFactory.makeSPT(parameters, classLoader, geoContext);
	return new Function<String, SpatialStrategy>() {

		@Override
		public SpatialStrategy apply(String field) {
			return new RecursivePrefixTreeStrategy(spt, GEO_FIELD_PREFIX + field);
		}

	};
}
 
Example #4
Source File: SpatialExample.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void init() {
  //Typical geospatial context
  //  These can also be constructed from SpatialContextFactory
  this.ctx = SpatialContext.GEO;

  int maxLevels = 11;//results in sub-meter precision for geohash
  //TODO demo lookup by detail distance
  //  This can also be constructed from SpatialPrefixTreeFactory
  SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);

  this.strategy = new RecursivePrefixTreeStrategy(grid, "myGeoField");

  this.directory = new ByteBuffersDirectory();
}
 
Example #5
Source File: SpatialRecursivePrefixTreeFieldType.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #6
Source File: OLuceneSpatialIndexManager.java    From orientdb-lucene with Apache License 2.0 5 votes vote down vote up
public OLuceneSpatialIndexManager(OShapeFactory factory) {
  super();
  this.ctx = SpatialContext.GEO;
  this.factory = factory;
  SpatialPrefixTree grid = new GeohashPrefixTree(ctx, 11);
  this.strategy = new RecursivePrefixTreeStrategy(grid, "location");
}
 
Example #7
Source File: CompositeSpatialStrategy.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public CompositeSpatialStrategy(String fieldName,
                                RecursivePrefixTreeStrategy indexStrategy, SerializedDVStrategy geometryStrategy) {
  super(indexStrategy.getSpatialContext(), fieldName);//field name; unused
  this.indexStrategy = indexStrategy;
  this.geometryStrategy = geometryStrategy;
}
 
Example #8
Source File: CompositeSpatialStrategy.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public RecursivePrefixTreeStrategy getIndexStrategy() {
  return indexStrategy;
}
 
Example #9
Source File: Geo3dRptTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
protected RecursivePrefixTreeStrategy newRPT() {
  final RecursivePrefixTreeStrategy rpt = new RecursivePrefixTreeStrategy(this.grid,
      getClass().getSimpleName() + "_rpt");
  rpt.setDistErrPct(0.10);//not too many cells
  return rpt;
}
 
Example #10
Source File: CompositeStrategyTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
protected RecursivePrefixTreeStrategy newRPT() {
  final RecursivePrefixTreeStrategy rpt = new RecursivePrefixTreeStrategy(this.grid,
      getClass().getSimpleName() + "_rpt");
  rpt.setDistErrPct(0.10);//not too many cells
  return rpt;
}
 
Example #11
Source File: RptWithGeometrySpatialField.java    From lucene-solr with Apache License 2.0 3 votes vote down vote up
@Override
protected CompositeSpatialStrategy newSpatialStrategy(String fieldName) {
  // We use the same field name for both sub-strategies knowing there will be no conflict for these two

  RecursivePrefixTreeStrategy rptStrategy = rptFieldType.newSpatialStrategy(fieldName);

  SerializedDVStrategy geomStrategy = new CachingSerializedDVStrategy(ctx, fieldName);

  return new CompositeSpatialStrategy(fieldName, rptStrategy, geomStrategy);
}