bchapuis commented on code in PR #712:
URL:
https://github.com/apache/incubator-baremaps/pull/712#discussion_r1245594310
##########
baremaps-server/src/main/java/org/apache/baremaps/server/GeocoderResource.java:
##########
@@ -54,28 +58,43 @@
@GET
@javax.ws.rs.Path("/api/geocoder")
- public Response getIpToLocation(
+ public Response searchLocations(
@QueryParam("queryText") String queryText,
@QueryParam("countryCode") @DefaultValue("") String countryCode,
- @QueryParam("limit") @DefaultValue("10") int limit) throws IOException {
+ @QueryParam("limit") @DefaultValue("10") int limit) {
if (queryText == null) {
throw new
WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
.entity("The queryText parameter is mandatory").build());
}
- var query = new
GeonamesQueryBuilder().queryText(queryText).countryCode(countryCode).build();
- var searcher = searcherManager.acquire();
try {
- var result = searcher.search(query, limit);
- var results =
- Arrays.stream(result.scoreDocs).map(scoreDoc -> asResult(searcher,
scoreDoc)).toList();
- return Response.status(200).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
- .header(CONTENT_TYPE, APPLICATION_JSON).entity(new
GeocoderResponse(results)).build();
- } catch (IllegalArgumentException e) {
- return Response.status(400).entity(e.getMessage()).build();
+ IndexSearcher searcher = searcherManager.acquire();
+ try {
+ // Querying to search location uses AND operator between terms such as
every term "adds up"
+ // Examples of queryText:
+ // - "paris", returns paris in france in first results (i.e because of
scoring with
+ // population)
+ // - "paris brazil", returns paris in brazil and not paris in france.
+ var query = new GeonamesQueryBuilder()
+
.queryText(queryText).countryCode(countryCode).withScoringByPopulation()
+ .withAndOperator()
+ .build();
+
+ var result = searcher.search(query, limit);
+ var results =
+ Arrays.stream(result.scoreDocs).map(scoreDoc -> asResult(searcher,
scoreDoc)).toList();
+ return
Response.status(Response.Status.OK).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
+ .header(CONTENT_TYPE, APPLICATION_JSON).entity(new
GeocoderResponse(results)).build();
+ } catch (IllegalArgumentException e) {
+ return
Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
Review Comment:
Let's log another issue to address these warnings.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]