/** * Target the given field in the "within" predicate. * <p> * Multiple fields may be targeted by the same predicate: * the predicate will match if <em>any</em> targeted field matches. * * @param absoluteFieldPath The absolute path (from the document root) of the targeted field. * @return A {@link SpatialWithinPredicateFieldSetContext} allowing to * continue the definition of the spatial predicate. */ default SpatialWithinPredicateFieldSetContext onField(String absoluteFieldPath) { return onFields( absoluteFieldPath ); }
@Test public void boundingBox_error_null() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "spatial().within().boundingBox() predicate with null bounding box", () -> searchTarget.predicate().spatial().within().onField( "geoPoint" ).boundingBox( null ) ) .assertThrown() .isInstanceOf( IllegalArgumentException.class ) .hasMessageContaining( "HSEARCH900000" ); }
.predicate( f -> f.spatial().within().onField( "geoPoint" ).orField( "geoPoint_1" ).polygon( POLYGON_1 ).toPredicate() ) .build(); .predicate( f -> f.spatial().within().onField( "geoPoint" ).orField( "geoPoint_1" ).polygon( POLYGON_2_1 ).toPredicate() ) .build(); .predicate( f -> f.spatial().within().onField( "geoPoint" ).orFields( "geoPoint_1" ).orFields( "geoPoint_2" ) .polygon( POLYGON_2 ) .toPredicate() .predicate( f -> f.spatial().within().onField( "geoPoint" ).orFields( "geoPoint_1" ).orFields( "geoPoint_2" ) .polygon( POLYGON_1_1 ) .toPredicate() .predicate( f -> f.spatial().within().onField( "geoPoint" ).orFields( "geoPoint_1" ).orFields( "geoPoint_2" ) .polygon( POLYGON_2_2 ) .toPredicate() .predicate( f -> f.spatial().within().onFields( "geoPoint", "geoPoint_2" ).polygon( POLYGON_2 ).toPredicate() ) .build(); .predicate( f -> f.spatial().within().onFields( "geoPoint", "geoPoint_2" ).polygon( POLYGON_1_2 ).toPredicate() ) .build();
@Test public void polygon_error_null() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "spatial().within().boundingBox() predicate with null polygon", () -> searchTarget.predicate().spatial().within().onField( "geoPoint" ).polygon( null ) ) .assertThrown() .isInstanceOf( IllegalArgumentException.class ) .hasMessageContaining( "HSEARCH900000" ); }
.predicate( f -> f.spatial().within().onField( "geoPoint" ).orField( "geoPoint_1" ).boundingBox( BOUNDING_BOX_1 ).toPredicate() ) .build(); .predicate( f -> f.spatial().within().onField( "geoPoint" ).orField( "geoPoint_1" ).boundingBox( BOUNDING_BOX_2_1 ).toPredicate() ) .build(); .predicate( f -> f.spatial().within().onField( "geoPoint" ).orFields( "geoPoint_1" ).orFields( "geoPoint_2" ) .boundingBox( BOUNDING_BOX_2 ) .toPredicate() .predicate( f -> f.spatial().within().onField( "geoPoint" ).orFields( "geoPoint_1" ).orFields( "geoPoint_2" ) .boundingBox( BOUNDING_BOX_1_1 ) .toPredicate() .predicate( f -> f.spatial().within().onField( "geoPoint" ).orFields( "geoPoint_1" ).orFields( "geoPoint_2" ) .boundingBox( BOUNDING_BOX_2_2 ) .toPredicate() .predicate( f -> f.spatial().within().onFields( "geoPoint", "geoPoint_2" ).boundingBox( BOUNDING_BOX_2 ).toPredicate() ) .build(); .predicate( f -> f.spatial().within().onFields( "geoPoint", "geoPoint_2" ).boundingBox( BOUNDING_BOX_1_2 ).toPredicate() ) .build();
@Test public void circle_error_null() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "spatial().within().circle() predicate with null center", () -> searchTarget.predicate().spatial().within().onField( "geoPoint" ) .circle( null, 100 ) ) .assertThrown() .isInstanceOf( IllegalArgumentException.class ) .hasMessageContaining( "HSEARCH900000" ); SubTest.expectException( "spatial().within().circle() predicate with null distance unit", () -> searchTarget.predicate().spatial().within().onField( "geoPoint" ) .circle( GeoPoint.of( 45, 4 ), 100, null ) ) .assertThrown() .isInstanceOf( IllegalArgumentException.class ) .hasMessageContaining( "HSEARCH900000" ); }
/** * Target the given field in the "within" predicate. * <p> * Multiple fields may be targeted by the same predicate: * the predicate will match if <em>any</em> targeted field matches. * * @param absoluteFieldPath The absolute path (from the document root) of the targeted field. * @return A {@link SpatialWithinPredicateFieldSetContext} allowing to * continue the definition of the spatial predicate. */ default SpatialWithinPredicateFieldSetContext onField(String absoluteFieldPath) { return onFields( absoluteFieldPath ); }
@Test public void unknown_field() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "spatial().within().boundingBox() predicate on unknown field", () -> searchTarget.predicate().spatial().within().onField( "unknown_field" ) .boundingBox( BOUNDING_BOX_1 ).toPredicate() ) .assertThrown() .isInstanceOf( SearchException.class ) .hasMessageContaining( "Unknown field" ) .hasMessageContaining( "'unknown_field'" ); }
@Test public void unknown_field() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "spatial().within().polygon() predicate on unknown field", () -> searchTarget.predicate().spatial().within().onField( "unknown_field" ) .polygon( POLYGON_1 ).toPredicate() ) .assertThrown() .isInstanceOf( SearchException.class ) .hasMessageContaining( "Unknown field" ) .hasMessageContaining( "'unknown_field'" ); }
@Test public void unknown_field() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "spatial().within().circle() predicate on unknown field", () -> searchTarget.predicate().spatial().within().onField( "unknown_field" ) .circle( METRO_GARIBALDI, 100 ).toPredicate() ) .assertThrown() .isInstanceOf( SearchException.class ) .hasMessageContaining( "Unknown field" ) .hasMessageContaining( "'unknown_field'" ); } }
@Test public void unsupported_field_types() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "spatial().within().boundingBox() predicate on field with unsupported type", () -> searchTarget.predicate().spatial().within().onField( "string" ).boundingBox( BOUNDING_BOX_1 ) ) .assertThrown() .isInstanceOf( SearchException.class ) .hasMessageContaining( "Spatial predicates are not supported by" ) .satisfies( FailureReportUtils.hasContext( EventContexts.fromIndexFieldAbsolutePath( "string" ) ) ); }
@Test public void unsupported_field_types() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "spatial().within().polygon() predicate on field with unsupported type", () -> searchTarget.predicate().spatial().within().onField( "string" ).polygon( POLYGON_1 ) ) .assertThrown() .isInstanceOf( SearchException.class ) .hasMessageContaining( "Spatial predicates are not supported by" ) .satisfies( FailureReportUtils.hasContext( EventContexts.fromIndexFieldAbsolutePath( "string" ) ) ); }
@Test public void unsupported_field_types() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SubTest.expectException( "spatial().within().circle() predicate on field with unsupported type", () -> searchTarget.predicate().spatial().within() .onField( "string" ) .circle( METRO_GARIBALDI, 400 ) .toPredicate() ) .assertThrown() .isInstanceOf( SearchException.class ) .hasMessageContaining( "Spatial predicates are not supported by" ) .satisfies( FailureReportUtils.hasContext( EventContexts.fromIndexFieldAbsolutePath( "string" ) ) ); }
@Test public void within_polygon() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SearchQuery<DocumentReference> query = searchTarget.query() .asReference() .predicate( f -> f.spatial().within().onField( "geoPoint" ).polygon( POLYGON_2 ).toPredicate() ) .build(); assertThat( query ) .hasDocRefHitsAnyOrder( INDEX_NAME, IMOUTO_ID, CHEZ_MARGOTTE_ID ); query = searchTarget.query() .asReference() .predicate( f -> f.spatial().within().onField( "geoPoint" ).polygon( POLYGON_1 ).toPredicate() ) .build(); assertThat( query ) .hasDocRefHitsAnyOrder( INDEX_NAME, OURSON_QUI_BOIT_ID, IMOUTO_ID ); }
@Test public void boundingBox_consistency() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SearchQuery<DocumentReference> query = searchTarget.query() .asReference() .predicate( f -> f.spatial().within().onField( "geoPoint" ) .boundingBox( GeoBoundingBox.of( GeoPoint.of( 25, 23 ), GeoPoint.of( 24, 26 ) ) ) .toPredicate() ) .build(); assertThat( query ) .hasDocRefHitsAnyOrder( INDEX_NAME, ADDITIONAL_POINT_1_ID, ADDITIONAL_POINT_2_ID ); }
.predicate( f -> f.spatial().within().onField( "geoPoint" ).boundingBox( BOUNDING_BOX_2 ).toPredicate() ) .build(); .predicate( f -> f.spatial().within().onField( "geoPoint" ).boundingBox( BOUNDING_BOX_1 ).toPredicate() ) .build(); .predicate( f -> f.spatial().within().onField( "geoPoint" ) .boundingBox( BOUNDING_BOX_2.getTopLeft().getLatitude(), BOUNDING_BOX_2.getTopLeft().getLongitude(), BOUNDING_BOX_2.getBottomRight().getLatitude(), BOUNDING_BOX_2.getBottomRight().getLongitude() ) .predicate( f -> f.spatial().within().onField( "geoPoint" ) .boundingBox( BOUNDING_BOX_1.getTopLeft().getLatitude(), BOUNDING_BOX_1.getTopLeft().getLongitude(), BOUNDING_BOX_1.getBottomRight().getLatitude(), BOUNDING_BOX_1.getBottomRight().getLongitude() )
@Test public void boost() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SearchQuery<DocumentReference> query = searchTarget.query() .asReference() .predicate( f -> f.bool() .should( f.spatial().within().onField( "geoPoint" ).polygon( CHEZ_MARGOTTE_POLYGON ) ) .should( f.match().onField( "string" ).boostedTo( 42 ).matching( OURSON_QUI_BOIT_STRING ) ) .toPredicate() ) .sort( c -> c.byScore() ) .build(); assertThat( query ) .hasDocRefHitsExactOrder( INDEX_NAME, OURSON_QUI_BOIT_ID, CHEZ_MARGOTTE_ID ); query = searchTarget.query() .asReference() .predicate( f -> f.bool() .should( f.spatial().within().onField( "geoPoint" ).boostedTo( 42 ).polygon( CHEZ_MARGOTTE_POLYGON ) ) .should( f.match().onField( "string" ).matching( OURSON_QUI_BOIT_STRING ) ) .toPredicate() ) .sort( c -> c.byScore() ) .build(); assertThat( query ) .hasDocRefHitsExactOrder( INDEX_NAME, CHEZ_MARGOTTE_ID, OURSON_QUI_BOIT_ID ); }
@Test public void boost() { StubMappingSearchTarget searchTarget = indexManager.createSearchTarget(); SearchQuery<DocumentReference> query = searchTarget.query() .asReference() .predicate( f -> f.bool() .should( f.spatial().within().onField( "geoPoint" ).boundingBox( CHEZ_MARGOTTE_BOUNDING_BOX ) ) .should( f.match().onField( "string" ).boostedTo( 42 ).matching( OURSON_QUI_BOIT_STRING ) ) .toPredicate() ) .sort( c -> c.byScore() ) .build(); assertThat( query ) .hasDocRefHitsExactOrder( INDEX_NAME, OURSON_QUI_BOIT_ID, CHEZ_MARGOTTE_ID ); query = searchTarget.query() .asReference() .predicate( f -> f.bool() .should( f.spatial().within().onField( "geoPoint" ).boostedTo( 42 ).boundingBox( CHEZ_MARGOTTE_BOUNDING_BOX ) ) .should( f.match().onField( "string" ).matching( OURSON_QUI_BOIT_STRING ) ) .toPredicate() ) .sort( c -> c.byScore() ) .build(); assertThat( query ) .hasDocRefHitsExactOrder( INDEX_NAME, CHEZ_MARGOTTE_ID, OURSON_QUI_BOIT_ID ); }
.nest( f.spatial() .within() .onField( "copies.library.location" ) .circle( myLocation, maxDistanceInKilometers, DistanceUnit.KILOMETERS )