You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by "Perdjesk (via GitHub)" <gi...@apache.org> on 2023/07/03 06:27:16 UTC

[GitHub] [incubator-baremaps] Perdjesk commented on a diff in pull request #712: Geocoder: scoring by population, parsing query text support AND,OR operators

Perdjesk commented on code in PR #712:
URL: https://github.com/apache/incubator-baremaps/pull/712#discussion_r1250316258


##########
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:
   https://github.com/apache/incubator-baremaps/issues/713



-- 
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: commits-unsubscribe@baremaps.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org