Skip to content

Commit

Permalink
HTM-1091: Enable bbox filtering for Solr search (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
mprins authored Nov 12, 2024
2 parents ec1cef4 + ac6bab2 commit ef324ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/org/tailormap/api/solr/SolrHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ public SearchResponse findInIndex(
query.addFilterQuery(solrFilterQuery);
}
if (null != solrPoint && null != solrDistance) {
if (null == solrFilterQuery || !solrFilterQuery.startsWith("{!geofilt")) {
if (null == solrFilterQuery
|| !(solrFilterQuery.startsWith("{!geofilt") || solrFilterQuery.startsWith("{!bbox"))) {
query.addFilterQuery("{!geofilt sfield=" + INDEX_GEOM_FIELD + "}");
}
query.add("pt", solrPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,30 @@ void testSpatialQueryDistance() throws Exception {
.andExpect(jsonPath("$.documents[0].displayValues").isArray())
.andExpect(jsonPath("$.documents[0]." + INDEX_GEOM_FIELD).isString());
}

@Test
void testSpatialQueryDistanceWithBbox() throws Exception {
final String url = apiBasePath + layerWegdeelSqlServer + "/search";

mockMvc
.perform(
get(url)
.accept(MediaType.APPLICATION_JSON)
.with(setServletPath(url))
.param("q", "open")
.param("start", "0")
.param("fq", "{!bbox sfield=geometry}")
.param("pt", "133809 458811")
.param("d", "0.5"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.start").value(0))
.andExpect(jsonPath("$.total").value(2))
.andExpect(jsonPath("$.documents").isArray())
.andExpect(jsonPath("$.documents.length()").value(2))
.andExpect(jsonPath("$.documents[0].fid").isString())
.andExpect(jsonPath("$.documents[0].fid").value(startsWithIgnoringCase("wegdeel")))
.andExpect(jsonPath("$.documents[0].displayValues").isArray())
.andExpect(jsonPath("$.documents[0]." + INDEX_GEOM_FIELD).isString());
}
}

0 comments on commit ef324ba

Please sign in to comment.