Examples of SpatialArgs


Examples of org.apache.lucene.spatial.query.SpatialArgs

    return new SpatialArgs(SpatialOperation.Intersects, shape1);
  }

  private SpatialArgs makeArgs2() {
    final Shape shape2 = ctx.makeRectangle(0, 0, 20, 20);
    return new SpatialArgs(SpatialOperation.Intersects, shape2);
  }
View Full Code Here

Examples of org.apache.lucene.spatial.query.SpatialArgs

  @Test
  public void testContainsPairOverlap() throws IOException {
    setupQuadGrid(3);
    adoc("0", new ShapePair(ctx.makeRectangle(0, 33, -128, 128), ctx.makeRectangle(33, 128, -128, 128), true));
    commit();
    Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Contains,
        ctx.makeRectangle(0, 128, -16, 128)));
    SearchResults searchResults = executeQuery(query, 1);
    assertEquals(1, searchResults.numFound);
  }
View Full Code Here

Examples of org.apache.lucene.spatial.query.SpatialArgs

    setupQuadGrid(7);
    //one shape comprised of two parts, quite separated apart
    adoc("0", new ShapePair(ctx.makeRectangle(0, 10, -120, -100), ctx.makeRectangle(220, 240, 110, 125), false));
    commit();
    //query surrounds only the second part of the indexed shape
    Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.IsWithin,
        ctx.makeRectangle(210, 245, 105, 128)));
    SearchResults searchResults = executeQuery(query, 1);
    //we shouldn't find it because it's not completely within
    assertTrue(searchResults.numFound == 0);
  }
View Full Code Here

Examples of org.apache.lucene.spatial.query.SpatialArgs

    //query does NOT contain it; both indexed cells are leaves to the query, and
    // when expanded to the full grid cells, the top one's top row is disjoint
    // from the query and thus not a match.
    assertTrue(executeQuery(strategy.makeQuery(
        new SpatialArgs(SpatialOperation.IsWithin, ctx.makeRectangle(38, 192, -72, 56))
    ), 1).numFound==0);//no-match

    //this time the rect is a little bigger and is considered a match. It's a
    // an acceptable false-positive because of the grid approximation.
    assertTrue(executeQuery(strategy.makeQuery(
        new SpatialArgs(SpatialOperation.IsWithin, ctx.makeRectangle(38, 192, -72, 80))
    ), 1).numFound==1);//match
  }
View Full Code Here

Examples of org.apache.lucene.spatial.query.SpatialArgs

  }

  private void doTest(final SpatialOperation operation) throws IOException {
    //first show that when there's no data, a query will result in no results
    {
      Query query = strategy.makeQuery(new SpatialArgs(operation, randomRectangle()));
      SearchResults searchResults = executeQuery(query, 1);
      assertEquals(0, searchResults.numFound);
    }

    final boolean biasContains = (operation == SpatialOperation.Contains);

    //Main index loop:
    Map<String, Shape> indexedShapes = new LinkedHashMap<String, Shape>();
    Map<String, Shape> indexedShapesGS = new LinkedHashMap<String, Shape>();//grid snapped
    final int numIndexedShapes = randomIntBetween(1, 6);
    boolean indexedAtLeastOneShapePair = false;
    for (int i = 0; i < numIndexedShapes; i++) {
      String id = "" + i;
      Shape indexedShape;
      int R = random().nextInt(12);
      if (R == 0) {//1 in 12
        indexedShape = null;
      } else if (R == 1) {//1 in 12
        indexedShape = randomPoint();//just one point
      } else if (R <= 4) {//3 in 12
        //comprised of more than one shape
        indexedShape = randomShapePairRect(biasContains);
        indexedAtLeastOneShapePair = true;
      } else {
        indexedShape = randomRectangle();//just one rect
      }

      indexedShapes.put(id, indexedShape);
      indexedShapesGS.put(id, gridSnap(indexedShape));

      adoc(id, indexedShape);

      if (random().nextInt(10) == 0)
        commit();//intermediate commit, produces extra segments

    }
    //delete some documents randomly
    Iterator<String> idIter = indexedShapes.keySet().iterator();
    while (idIter.hasNext()) {
      String id = idIter.next();
      if (random().nextInt(10) == 0) {
        deleteDoc(id);
        idIter.remove();
        indexedShapesGS.remove(id);
      }
    }

    commit();

    //Main query loop:
    final int numQueryShapes = atLeast(20);
    for (int i = 0; i < numQueryShapes; i++) {
      int scanLevel = randomInt(grid.getMaxLevels());
      ((RecursivePrefixTreeStrategy) strategy).setPrefixGridScanLevel(scanLevel);

      final Shape queryShape;
      switch (randomInt(10)) {
        case 0: queryShape = randomPoint(); break;
// LUCENE-5549
//TODO debug: -Dtests.method=testWithin -Dtests.multiplier=3 -Dtests.seed=5F5294CE2E075A3E:AAD2F0F79288CA64
//        case 1:case 2:case 3:
//          if (!indexedAtLeastOneShapePair) { // avoids ShapePair.relate(ShapePair), which isn't reliable
//            queryShape = randomShapePairRect(!biasContains);//invert biasContains for query side
//            break;
//          }
        default: queryShape = randomRectangle();
      }
      final Shape queryShapeGS = gridSnap(queryShape);

      final boolean opIsDisjoint = operation == SpatialOperation.IsDisjointTo;

      //Generate truth via brute force:
      // We ensure true-positive matches (if the predicate on the raw shapes match
      //  then the search should find those same matches).
      // approximations, false-positive matches
      Set<String> expectedIds = new LinkedHashSet<String>();//true-positives
      Set<String> secondaryIds = new LinkedHashSet<String>();//false-positives (unless disjoint)
      for (Map.Entry<String, Shape> entry : indexedShapes.entrySet()) {
        String id = entry.getKey();
        Shape indexedShapeCompare = entry.getValue();
        if (indexedShapeCompare == null)
          continue;
        Shape queryShapeCompare = queryShape;

        if (operation.evaluate(indexedShapeCompare, queryShapeCompare)) {
          expectedIds.add(id);
          if (opIsDisjoint) {
            //if no longer intersect after buffering them, for disjoint, remember this
            indexedShapeCompare = indexedShapesGS.get(id);
            queryShapeCompare = queryShapeGS;
            if (!operation.evaluate(indexedShapeCompare, queryShapeCompare))
              secondaryIds.add(id);
          }
        } else if (!opIsDisjoint) {
          //buffer either the indexed or query shape (via gridSnap) and try again
          if (operation == SpatialOperation.Intersects) {
            indexedShapeCompare = indexedShapesGS.get(id);
            queryShapeCompare = queryShapeGS;
            //TODO Unfortunately, grid-snapping both can result in intersections that otherwise
            // wouldn't happen when the grids are adjacent. Not a big deal but our test is just a
            // bit more lenient.
          } else if (operation == SpatialOperation.Contains) {
            indexedShapeCompare = indexedShapesGS.get(id);
          } else if (operation == SpatialOperation.IsWithin) {
            queryShapeCompare = queryShapeGS;
          }
          if (operation.evaluate(indexedShapeCompare, queryShapeCompare))
            secondaryIds.add(id);
        }
      }

      //Search and verify results
      SpatialArgs args = new SpatialArgs(operation, queryShape);
      if (queryShape instanceof ShapePair)
        args.setDistErrPct(0.0);//a hack; we want to be more detailed than gridSnap(queryShape)
      Query query = strategy.makeQuery(args);
      SearchResults got = executeQuery(query, 100);
      Set<String> remainingExpectedIds = new LinkedHashSet<String>(expectedIds);
      for (SearchResult result : got.results) {
        String id = result.getId();
View Full Code Here

Examples of org.apache.lucene.spatial.query.SpatialArgs

  @Test
  /** LUCENE-4464 */
  public void testCloseButNoMatch() throws Exception {
    getAddAndVerifyIndexedDocuments("LUCENE-4464.txt");
    SpatialArgs args = q(
        "POLYGON((-93.18100824442227 45.25676372469945," +
            "-93.23182001200654 45.21421290799412," +
            "-93.16315546122038 45.23742639412364," +
            "-93.18100824442227 45.25676372469945))",
        LUCENE_4464_distErrPct);
View Full Code Here

Examples of org.apache.lucene.spatial.query.SpatialArgs

    //did not find poly 1 !
  }

  private SpatialArgs q(String shapeStr, double distErrPct) throws ParseException {
    Shape shape = ctx.readShapeFromWkt(shapeStr);
    SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, shape);
    args.setDistErrPct(distErrPct);
    return args;
  }
View Full Code Here

Examples of org.apache.lucene.spatial.query.SpatialArgs

    addDocument(doc);

    Point upperleft = ctx.makePoint(-122.88, 48.54);
    Point lowerright = ctx.makePoint(-122.82, 48.62);
   
    Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(upperleft, lowerright)));
    commit();
   
    TopDocs search = indexSearcher.search(query, 10);
    ScoreDoc[] scoreDocs = search.scoreDocs;
    for (ScoreDoc scoreDoc : scoreDocs) {
View Full Code Here

Examples of org.apache.lucene.spatial.query.SpatialArgs

    double distDEG = DistanceUtils.dist2Degrees(distKM, DistanceUtils.EARTH_MEAN_RADIUS_KM);
    Shape shape = ctx.makeCircle(pt, distDEG);
    if (bbox)
      shape = shape.getBoundingBox();

    SpatialArgs args = new SpatialArgs(op,shape);
    //args.setDistPrecision(0.025);
    Query query;
    if (random().nextBoolean()) {
      query = strategy.makeQuery(args);
    } else {
View Full Code Here

Examples of org.apache.lucene.spatial.query.SpatialArgs

    return queries.toArray(new Query[queries.size()]);
  }


  protected Query makeQueryFromShape(Shape shape) {
    SpatialArgs args = new SpatialArgs(operation, shape);
    if (!Double.isNaN(distErrPct))
      args.setDistErrPct(distErrPct);

    if (score) {
      ValueSource valueSource = strategy.makeDistanceValueSource(shape.getCenter());
      return new CustomScoreQuery(strategy.makeQuery(args), new FunctionQuery(valueSource));
    } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.