Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions src/query/geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,7 @@ impl IndexedShape {

/// Geo Bounding Box Query
#[derive(Debug, Serialize)]
pub struct GeoBoundingBoxQuery(FieldBasedQuery<GeoBoundingBoxQueryInner, NoOuter>);

#[derive(Debug, Default, Serialize)]
pub struct GeoBoundingBoxQueryInner {
geo_box: GeoBox,
#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
coerce: Option<bool>,
#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
ignore_malformed: Option<bool>,
#[serde(skip_serializing_if = "ShouldSkip::should_skip", rename = "type")]
filter_type: Option<Type>,
}
pub struct GeoBoundingBoxQuery(FieldBasedQuery<GeoBox, NoOuter>);

impl Query {
pub fn build_geo_bounding_box<A, B>(field: A, geo_box: B) -> GeoBoundingBoxQuery
Expand All @@ -149,19 +138,16 @@ impl Query {
{
GeoBoundingBoxQuery(FieldBasedQuery::new(
field.into(),
GeoBoundingBoxQueryInner {
geo_box: geo_box.into(),
..Default::default()
},
geo_box.into(),
NoOuter,
))
}
}

impl GeoBoundingBoxQuery {
add_inner_field!(with_coerce, coerce, bool);
add_inner_field!(with_ignore_malformed, ignore_malformed, bool);
add_inner_field!(with_type, filter_type, Type);
//add_inner_field!(with_coerce, coerce, bool);
//add_inner_field!(with_ignore_malformed, ignore_malformed, bool);
//add_inner_field!(with_type, filter_type, Type);

build!(GeoBoundingBox);
}
Expand Down Expand Up @@ -455,6 +441,27 @@ pub mod tests {
client.refresh().with_indexes(&[index_name]).send().unwrap();
}

#[test]
fn test_geobbox_query() {
let index_name = "test_geobbox_query";
let mut client = make_client();

clean_db(&mut client, index_name);
setup_test_data(&mut client, index_name);

let all_results: SearchResult<GeoTestDocument> = client
.search_query()
.with_indexes(&[index_name])
.with_query(
&Query::build_geo_bounding_box("geojson_field", ((1.1, 1.1), (0.9, 0.9)))
.build(),
)
.send()
.unwrap();
// Only p1 should be returned
assert_eq!(1, all_results.hits.total);
}

#[test]
fn test_geoshape_search_point() {
let index_name = "test_geoshape_search_point";
Expand Down