This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
The following commit(s) were added to refs/heads/main by this push:
new fe1a9b9e Add IPLoc precision levels and metadata fields in iploc
database (#724)
fe1a9b9e is described below
commit fe1a9b9ef2e72983fba973170993a079bd0c7792
Author: Perdjesk <[email protected]>
AuthorDate: Sun Jul 30 20:02:56 2023 +0200
Add IPLoc precision levels and metadata fields in iploc database (#724)
* Bundle of progress around search in geonames index
* Change logic in IpLocMapper according to IpLocPrecision introduction
* IpLoc API with geocoderInput, source, precision, locationSource
* Finer precision, remove location_source, replace apache-commons usages
with guava
---
.../baremaps/geocoder/GeonamesDocumentMapper.java | 2 +-
.../baremaps/geocoder/GeonamesQueryBuilder.java | 18 +++-
.../org/apache/baremaps/iploc/IpLocMapper.java | 119 +++++++++++----------
.../org/apache/baremaps/iploc/IpLocObject.java | 12 ++-
.../{IpLocObject.java => IpLocPrecision.java} | 15 +--
.../org/apache/baremaps/iploc/IpLocRepository.java | 90 +++++++---------
.../baremaps/geocoder/GeonamesIndexTest.java | 4 +-
.../baremaps/geocoder/GeonamesReaderTest.java | 2 +-
.../org/apache/baremaps/iploc/IpLocObjectTest.java | 10 +-
.../test/resources/geonames/geocoder_sample.txt | 3 +-
.../src/test/resources/ripe/simple_nic_sample.txt | 15 ++-
.../apache/baremaps/server/GeocoderResource.java | 4 +-
.../org/apache/baremaps/server/IpLocResource.java | 12 ++-
.../src/main/resources/iploc/index.html | 10 +-
14 files changed, 161 insertions(+), 155 deletions(-)
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/GeonamesDocumentMapper.java
b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/GeonamesDocumentMapper.java
index cd6177ac..def2af5f 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/GeonamesDocumentMapper.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/GeonamesDocumentMapper.java
@@ -37,7 +37,7 @@ public class GeonamesDocumentMapper implements
Function<GeonamesRecord, Document
document.add(new TextField("asciiname", record.getAsciiname(),
Field.Store.YES));
document.add(new StoredField("alternatenames",
record.getAlternatenames()));
document.add(new StringField("featureClass", record.getFeatureClass(),
Field.Store.YES));
- document.add(new StoredField("featureCode", record.getFeatureCode()));
+ document.add(new StringField("featureCode", record.getFeatureCode(),
Field.Store.YES));
document.add(new StoredField("cc2", record.getCc2()));
document.add(new StoredField("admin1Code", record.getAdmin1Code()));
document.add(new StoredField("admin2Code", record.getAdmin2Code()));
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/GeonamesQueryBuilder.java
b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/GeonamesQueryBuilder.java
index 561cb321..34735bc8 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/GeonamesQueryBuilder.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/GeonamesQueryBuilder.java
@@ -14,6 +14,7 @@ package org.apache.baremaps.geocoder;
+import com.google.common.base.Strings;
import java.text.ParseException;
import java.util.Map;
import org.apache.lucene.analysis.Analyzer;
@@ -44,6 +45,7 @@ public class GeonamesQueryBuilder {
private boolean scoringByPopulation;
private boolean andOperator;
+ private String featureCode;
public GeonamesQueryBuilder() {
@@ -67,15 +69,20 @@ public class GeonamesQueryBuilder {
/**
* The scoring will take into account the population
*/
- public GeonamesQueryBuilder withScoringByPopulation() {
+ public GeonamesQueryBuilder scoringByPopulation() {
this.scoringByPopulation = true;
return this;
}
+ public GeonamesQueryBuilder featureCode(String featureCode) {
+ this.featureCode = featureCode;
+ return this;
+ }
+
/**
* The queryText will be parsed with AND operator between terms instead of
OR.
*/
- public GeonamesQueryBuilder withAndOperator() {
+ public GeonamesQueryBuilder andOperator() {
this.andOperator = true;
return this;
}
@@ -86,6 +93,7 @@ public class GeonamesQueryBuilder {
if (queryText != null) {
var queryTextEsc = QueryParser.escape(queryText);
if (!queryTextEsc.isBlank()) {
+ // Changing the fields here might affect queries using queryText.
var fieldWeights = Map.of("name", 1f, "asciiname", 1f, "country", 1f,
"countryCode", 1f);
var parser = new SimpleQueryParser(analyzer, fieldWeights);
if (andOperator) {
@@ -106,6 +114,12 @@ public class GeonamesQueryBuilder {
}
}
+
+ if (!Strings.isNullOrEmpty(featureCode)) {
+ var featureCodeQuery = new TermQuery(new Term("featureCode",
featureCode));
+ builder.add(featureCodeQuery, BooleanClause.Occur.MUST);
+ }
+
if (scoringByPopulation) {
var query = builder.build();
// ln(1+population) to tolerate entries with population=0
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocMapper.java
b/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocMapper.java
index 0215afa2..e2e9d2da 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocMapper.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocMapper.java
@@ -13,15 +13,18 @@
package org.apache.baremaps.iploc;
+import com.google.common.base.Strings;
import com.google.common.net.InetAddresses;
import java.io.IOException;
import java.text.ParseException;
+import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.regex.Pattern;
import net.ripe.ipresource.IpResourceRange;
import org.apache.baremaps.geocoder.GeonamesQueryBuilder;
import org.apache.baremaps.utils.IsoCountriesUtils;
+import org.apache.lucene.search.Query;
import org.apache.lucene.search.SearcherManager;
import org.locationtech.jts.geom.Coordinate;
import org.slf4j.Logger;
@@ -85,80 +88,64 @@ public class IpLocMapper implements Function<NicObject,
Optional<IpLocObject>> {
inetRange,
location.get(),
network,
- attributes.get("country")));
+ attributes.get("country"),
+ attributes.get("source"),
+ IpLocPrecision.GEOLOC));
}
}
- // If there is an address we use that address to query the geocoder
- if (attributes.containsKey("address")) {
- var location = findLocation(attributes.get("address"),
attributes.get("country"));
- if (location.isPresent()) {
- return Optional.of(new IpLocObject(
- attributes.get("address"),
- inetRange,
- location.get(),
- network,
- attributes.get("country")));
+ // If there is a country, we use that with a cherry-picked list of
fields to query the
+ // geocoder with confidence to find a relevant precise location,
+ // in the worst case the error is within a country
+ List<String> searchedFields = List.of("descr", "netname");
+ // at least one of a searchedField is present and the country is present.
+ if (attributes.keySet().stream().anyMatch(searchedFields::contains)
+ && attributes.containsKey("country")) {
+ // build a query text string out of the cherry-picked fields
+ var queryTextBuilder = new StringBuilder();
+ for (String field : searchedFields) {
+ if (!Strings.isNullOrEmpty(attributes.get(field))) {
+ queryTextBuilder.append(attributes.get(field)).append(" ");
+ }
}
- }
- // If there is a description we use that description to query the
geocoder
- if (attributes.containsKey("descr")) {
- var location = findLocation(attributes.get("descr"),
attributes.get("country"));
+ String queryText = queryTextBuilder.toString();
+ var location = findLocationInCountry(queryText,
attributes.get("country"));
if (location.isPresent()) {
return Optional.of(new IpLocObject(
- attributes.get("descr"),
+ queryText,
inetRange,
location.get(),
network,
- attributes.get("country")));
- }
- }
-
- // If there is a name we use that name to query the geocoder
- if (attributes.containsKey("name")) {
- var location = findLocation(attributes.get("name"),
attributes.get("country"));
- if (location.isPresent()) {
- return Optional.of(new IpLocObject(attributes.get("name"),
- inetRange,
- location.get(),
- network, attributes.get("country")));
- }
- }
-
- // If there is a country that follows the ISO format we use that
country's actual name from
- // the iso country map to query the geocoder
- if (attributes.containsKey("country")
- &&
IsoCountriesUtils.containsCountry(attributes.get("country").toUpperCase())) {
- var countryUppercase = attributes.get("country").toUpperCase();
- var location =
- findLocation(IsoCountriesUtils.getCountry(countryUppercase),
countryUppercase);
- if (location.isPresent()) {
- return Optional.of(new IpLocObject(
- IsoCountriesUtils.getCountry(countryUppercase),
- inetRange,
- location.get(),
- network,
- countryUppercase));
+ attributes.get("country"),
+ attributes.get("source"),
+ IpLocPrecision.GEOCODER));
}
}
- // If there is a country that did not follow the ISO format we will
query using the country
- // has plain text
+ // If there is a country get the location of country
if (attributes.containsKey("country")) {
- var location = findLocation(attributes.get("country"), "");
+ var location = findCountryLocation(attributes.get("country"));
if (location.isPresent()) {
return Optional.of(new IpLocObject(
attributes.get("country"),
inetRange,
location.get(),
network,
- attributes.get("country")));
+ attributes.get("country"),
+ attributes.get("source"),
+ IpLocPrecision.COUNTRY));
}
}
- return Optional.empty();
-
+ return Optional.of(new IpLocObject(
+ null,
+ inetRange,
+ new Coordinate(),
+ network,
+ null,
+ attributes.get("source"),
+ IpLocPrecision.WORLD));
} catch (Exception e) {
logger.warn("Error while mapping nic object to ip loc object", e);
logger.warn("Nic object attributes:");
@@ -174,21 +161,35 @@ public class IpLocMapper implements Function<NicObject,
Optional<IpLocObject>> {
}
}
+ private Optional<Coordinate> findCountryLocation(String country)
+ throws IOException, ParseException {
+ GeonamesQueryBuilder geonamesQuery = new
GeonamesQueryBuilder().featureCode("PCLI");
+ if (IsoCountriesUtils.containsCountry(country.toUpperCase())) {
+ geonamesQuery.countryCode(country.toUpperCase());
+ } else {
+ geonamesQuery.queryText(country).build();
+ }
+ return findLocation(geonamesQuery.build());
+ }
+
+ private Optional<Coordinate> findLocationInCountry(String terms, String
countryCode)
+ throws IOException, ParseException {
+ var geonamesQuery =
+ new
GeonamesQueryBuilder().queryText(terms).countryCode(countryCode).build();
+ return findLocation(geonamesQuery);
+ }
+
/**
- * Uses the geocoder to find the location of the specified search terms.
+ * Uses the geocoder to find the location of the specified query
*
- * @param searchTerms the search terms
- * @param countryCode the country code
* @return an {@code Optional} containing the location of the search terms
* @throws IOException if an I/O error occurs
*/
- private Optional<Coordinate> findLocation(String searchTerms, String
countryCode)
- throws IOException, ParseException {
+ private Optional<Coordinate> findLocation(Query query)
+ throws IOException {
var indexSearcher = searcherManager.acquire();
- var geonamesQuery =
- new
GeonamesQueryBuilder().queryText(searchTerms).countryCode(countryCode).build();
- var topDocs = indexSearcher.search(geonamesQuery, 1);
+ var topDocs = indexSearcher.search(query, 1);
if (topDocs.scoreDocs.length == 0) {
return Optional.empty();
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocObject.java
b/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocObject.java
index ed5889eb..e5849892 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocObject.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocObject.java
@@ -14,12 +14,18 @@ package org.apache.baremaps.iploc;
import org.locationtech.jts.geom.Coordinate;
-/** A record representing an IP associated with a location. */
+/**
+ * A record representing an IP associated with a location.
+ */
public record IpLocObject(
- String address,
+ String geocoderInput,
InetRange inetRange,
Coordinate coordinate,
String network,
- String country) {
+ String country,
+
+ String source,
+
+ IpLocPrecision precision) {
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocObject.java
b/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocPrecision.java
similarity index 70%
copy from baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocObject.java
copy to
baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocPrecision.java
index ed5889eb..d351c7e9 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocObject.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocPrecision.java
@@ -12,14 +12,9 @@
package org.apache.baremaps.iploc;
-import org.locationtech.jts.geom.Coordinate;
-
-/** A record representing an IP associated with a location. */
-public record IpLocObject(
- String address,
- InetRange inetRange,
- Coordinate coordinate,
- String network,
- String country) {
-
+public enum IpLocPrecision {
+ GEOLOC,
+ GEOCODER,
+ COUNTRY,
+ WORLD
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocRepository.java
b/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocRepository.java
index 9f554c90..b8e7abfd 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocRepository.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocRepository.java
@@ -39,13 +39,15 @@ public final class IpLocRepository {
private static final String CREATE_TABLE = """
CREATE TABLE IF NOT EXISTS inetnum_locations (
id integer PRIMARY KEY,
- address text NOT NULL,
+ geocoder_input text,
ip_start blob,
ip_end blob,
longitude real,
latitude real,
network text,
- country text
+ country text,
+ source text,
+ precision text
)""";
private static final String CREATE_INDEX = """
@@ -53,18 +55,20 @@ public final class IpLocRepository {
private static final String INSERT_SQL =
"""
- INSERT INTO inetnum_locations(address, ip_start, ip_end, longitude,
latitude, network, country)
- VALUES(?,?,?,?,?,?,?)""";
+ INSERT INTO inetnum_locations(geocoder_input, ip_start, ip_end,
longitude, latitude, network, country, source, precision)
+ VALUES(?,?,?,?,?,?,?,?,?)""";
- private static final String SELECT_ALL_SQL = """
- SELECT id, address, ip_start, ip_end, longitude, latitude, network,
country
- FROM inetnum_locations;""";
+ private static final String SELECT_ALL_SQL =
+ """
+ SELECT id, geocoder_input, ip_start, ip_end, longitude, latitude,
network, country, source, precision
+ FROM inetnum_locations;""";
- private static final String SELECT_ALL_BY_IP_SQL = """
- SELECT id, address, ip_start, ip_end, longitude, latitude, network,
country
- FROM inetnum_locations
- WHERE ip_start <= ? AND ip_end >= ?
- ORDER BY ip_start DESC, ip_end ASC;""";
+ private static final String SELECT_ALL_BY_IP_SQL =
+ """
+ SELECT id, geocoder_input, ip_start, ip_end, longitude, latitude,
network, country, source, precision
+ FROM inetnum_locations
+ WHERE ip_start <= ? AND ip_end >= ?
+ ORDER BY ip_start DESC, ip_end ASC;""";
private static final Logger logger =
LoggerFactory.getLogger(IpLocRepository.class);
@@ -127,16 +131,7 @@ public final class IpLocRepository {
ResultSet resultSet = statement.executeQuery()) {
// loop through the result set
while (resultSet.next()) {
- results.add(new IpLocObject(
- resultSet.getString("address"),
- new InetRange(
- fromByteArray(resultSet.getBytes("ip_start")),
- fromByteArray(resultSet.getBytes("ip_end"))),
- new Coordinate(
- resultSet.getDouble("longitude"),
- resultSet.getDouble("latitude")),
- resultSet.getString("network"),
- resultSet.getString("country")));
+ results.add(resultSetToPojo(resultSet));
}
} catch (SQLException e) {
logger.error("Unable to select inetnum locations", e);
@@ -144,6 +139,21 @@ public final class IpLocRepository {
return results;
}
+ private IpLocObject resultSetToPojo(ResultSet resultSet) throws SQLException
{
+ return new IpLocObject(
+ resultSet.getString("geocoder_input"),
+ new InetRange(
+ fromByteArray(resultSet.getBytes("ip_start")),
+ fromByteArray(resultSet.getBytes("ip_end"))),
+ new Coordinate(
+ resultSet.getDouble("longitude"),
+ resultSet.getDouble("latitude")),
+ resultSet.getString("network"),
+ resultSet.getString("country"),
+ resultSet.getString("source"),
+ IpLocPrecision.valueOf(resultSet.getString("precision")));
+ }
+
/**
* Returns the {@code IpLocObject} objects in the repository that contain
the specified IP.
*
@@ -158,16 +168,7 @@ public final class IpLocRepository {
statement.setBytes(2, inetAddress.getAddress());
try (var resultSet = statement.executeQuery();) {
while (resultSet.next()) {
- ipLocObjects.add(new IpLocObject(
- resultSet.getString("address"),
- new InetRange(
- fromByteArray(resultSet.getBytes("ip_start")),
- fromByteArray(resultSet.getBytes("ip_end"))),
- new Coordinate(
- resultSet.getDouble("longitude"),
- resultSet.getDouble("latitude")),
- resultSet.getString("network"),
- resultSet.getString("country")));
+ ipLocObjects.add(resultSetToPojo(resultSet));
}
}
} catch (SQLException e) {
@@ -176,27 +177,6 @@ public final class IpLocRepository {
return ipLocObjects;
}
- /**
- * Saves the {@code IpLocObject} object in the repository.
- *
- * @param ipLocObject the {@code IpLocObject} object
- */
- public void save(IpLocObject ipLocObject) {
- try (var connection = dataSource.getConnection();
- var statement = connection.prepareStatement(INSERT_SQL)) {
- statement.setString(1, ipLocObject.address());
- statement.setBytes(2, ipLocObject.inetRange().start().getAddress());
- statement.setBytes(3, ipLocObject.inetRange().end().getAddress());
- statement.setDouble(4, ipLocObject.coordinate().getX());
- statement.setDouble(5, ipLocObject.coordinate().getY());
- statement.setString(6, ipLocObject.network());
- statement.setString(7, ipLocObject.country());
- statement.executeUpdate();
- } catch (SQLException e) {
- logger.error("Unable to save data", e);
- }
- }
-
/**
* Saves the {@code IpLocObject} objects in the repository.
*
@@ -207,13 +187,15 @@ public final class IpLocRepository {
var statement = connection.prepareStatement(INSERT_SQL);) {
connection.setAutoCommit(false);
for (IpLocObject ipLocObject : ipLocObjects) {
- statement.setString(1, ipLocObject.address());
+ statement.setString(1, ipLocObject.geocoderInput());
statement.setBytes(2, ipLocObject.inetRange().start().getAddress());
statement.setBytes(3, ipLocObject.inetRange().end().getAddress());
statement.setDouble(4, ipLocObject.coordinate().getX());
statement.setDouble(5, ipLocObject.coordinate().getY());
statement.setString(6, ipLocObject.network());
statement.setString(7, ipLocObject.country());
+ statement.setString(8, ipLocObject.source());
+ statement.setString(9, ipLocObject.precision().toString());
statement.addBatch();
}
statement.executeBatch();
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/geocoder/GeonamesIndexTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/geocoder/GeonamesIndexTest.java
index 60f2126a..1a660abd 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/geocoder/GeonamesIndexTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/geocoder/GeonamesIndexTest.java
@@ -77,7 +77,7 @@ public class GeonamesIndexTest {
@Test
void testAndQueryNoHits() throws Exception {
var geonamesQuery =
- new GeonamesQueryBuilder().queryText("vaduz
berlin").withAndOperator().countryCode("LI")
+ new GeonamesQueryBuilder().queryText("vaduz
berlin").andOperator().countryCode("LI")
.build();
var topDocs = searcher.search(geonamesQuery, 1);
assertEquals(0, topDocs.totalHits.value);
@@ -86,7 +86,7 @@ public class GeonamesIndexTest {
@Test
void testAndQuery() throws Exception {
var geonamesQuery =
- new GeonamesQueryBuilder().queryText("vaduz
liechtenstein").withAndOperator()
+ new GeonamesQueryBuilder().queryText("vaduz
liechtenstein").andOperator()
.countryCode("LI").build();
var topDocs = searcher.search(geonamesQuery, 1);
var doc =
searcher.doc(Arrays.stream(topDocs.scoreDocs).findFirst().get().doc);
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/geocoder/GeonamesReaderTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/geocoder/GeonamesReaderTest.java
index 76ab91ed..adf7a817 100644
---
a/baremaps-core/src/test/java/org/apache/baremaps/geocoder/GeonamesReaderTest.java
+++
b/baremaps-core/src/test/java/org/apache/baremaps/geocoder/GeonamesReaderTest.java
@@ -30,7 +30,7 @@ class GeonamesReaderTest {
var stream = reader.stream(inputStream);
var list = stream.collect(Collectors.toList());
- assertEquals(4, list.size());
+ assertEquals(5, list.size());
var record = list.get(0);
assertEquals(1, record.getGeonameid());
diff --git
a/baremaps-core/src/test/java/org/apache/baremaps/iploc/IpLocObjectTest.java
b/baremaps-core/src/test/java/org/apache/baremaps/iploc/IpLocObjectTest.java
index 9b38aa5c..5da13cfa 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/iploc/IpLocObjectTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/iploc/IpLocObjectTest.java
@@ -98,7 +98,7 @@ class IpLocObjectTest {
void findAll() {
iplocRepository.save(ipLocObjects);
List<IpLocObject> inetnumLocations = iplocRepository.findAll();
- assertEquals(7, inetnumLocations.size());
+ assertEquals(9, inetnumLocations.size());
}
@Test
@@ -106,7 +106,7 @@ class IpLocObjectTest {
iplocRepository.save(ipLocObjects);
List<IpLocObject> inetnumLocations =
iplocRepository.findByInetAddress(InetAddresses.forString("0.0.0.5"));
- assertEquals(4, inetnumLocations.size());
+ assertEquals(6, inetnumLocations.size());
}
@Test
@@ -120,14 +120,14 @@ class IpLocObjectTest {
@Test
void save() {
var range = IpResourceRange.parse("192.168.0.0/24");
- iplocRepository.save(new IpLocObject(
+ iplocRepository.save(List.of(new IpLocObject(
"Test",
new InetRange(
InetAddresses.forString(range.getStart().toString()),
InetAddresses.forString(range.getEnd().toString())),
new Coordinate(1, 1),
"Test",
- null));
+ null, "test", IpLocPrecision.COUNTRY)));
List<IpLocObject> getAllInetnumLocations = iplocRepository.findAll();
assertEquals(1, getAllInetnumLocations.size());
}
@@ -144,7 +144,7 @@ class IpLocObjectTest {
InetAddresses.forString(range.getEnd().toString())),
new Coordinate(1, 1),
"Test",
- null));
+ null, "test", IpLocPrecision.COUNTRY));
}
iplocRepository.save(inetnumLocations);
List<IpLocObject> getAllInetnumLocations = iplocRepository.findAll();
diff --git a/baremaps-core/src/test/resources/geonames/geocoder_sample.txt
b/baremaps-core/src/test/resources/geonames/geocoder_sample.txt
index 223e91fc..3166933a 100644
--- a/baremaps-core/src/test/resources/geonames/geocoder_sample.txt
+++ b/baremaps-core/src/test/resources/geonames/geocoder_sample.txt
@@ -1,4 +1,5 @@
1 HEIG HEIG Haute École d'ingénieurie et de gestion 1.111 1.111
T PK CH CH 0 2600
2508 Europe/Test 16.02.19
2 Yverdon-les-bains Yverdon-les-bains Yverdon-les-bains, Vaud
2.222 2.222 T PK CH CH
0 2574 2534 Europe/Test 16.02.19
3 Route de Cheseaux 1 Route de Cheseaux 1 Route de Cheseaux 1,
Yverdon 3.333 3.333 S PK CH CH
0 2108 2098 Europe/Test 18.07.10
-4 Switzerland Switzerland Switzerland 4.444 4.444 P
PK CH CH 0 570
Europe/Test 03.07.15
\ No newline at end of file
+4 Switzerland Switzerland Switzerland 4.444 4.444 P
PK CH CH 0 570
Europe/Test 03.07.15
+5 Switzerland Switzerland An Eilbheis,CH,Confederatio
Helvetica,Confederation Suisse,Confederazione Svizzera 47.00016
8.01427 A PCLI CH 00 8516543
931 Europe/Zurich 2023-01-02
diff --git a/baremaps-core/src/test/resources/ripe/simple_nic_sample.txt
b/baremaps-core/src/test/resources/ripe/simple_nic_sample.txt
index d0a7d1fc..1e676356 100644
--- a/baremaps-core/src/test/resources/ripe/simple_nic_sample.txt
+++ b/baremaps-core/src/test/resources/ripe/simple_nic_sample.txt
@@ -6,20 +6,25 @@ descr: Suisse
country: CH
note: The most simple entry
+inetnum: 0.0.0.0 - 0.0.0.255
+netname: anetwork in Yverdon
+country: CH
+note: Object with country and netname should be searched by fields
+
inetnum: 0.0.0.0 - 0.0.0.255
netname: Route de Cheseaux 1
descr: Route de Cheseaux 1
descr: Vaud
descr: Suisse
country: LI
-note: Test with wrong country code should not be indexed
+note: Test with wrong country code should not be indexed, test data geocoder
do no contain LI entries
inetnum: 0.0.0.0 - 0.0.0.255
netname: Route de Cheseaux 1
descr: Route de Cheseaux 1
descr: Vaud
descr: Suisse
-note: Entry without the country code should not filter on country
+note: Entry without the country code are indexed with WORLD precision
inetnum: 0.0.0.0/24
netname: Route de Cheseaux 1
@@ -37,12 +42,6 @@ descr: Suisse
country: CH
note: Test with values that have the maximum byte value
-inetnum: 0.0.0.1 - 0.0.0.2
-netname: Yverdon-les-bains
-address: Yverdon-les-bains, Vaud
-country: CH
-note: Test with an address instead of descr
-
inetnum: 0.0.0.3 - 0.0.0.10
netname: Geoloc
geoloc: 43.12 9.422212222
diff --git
a/baremaps-server/src/main/java/org/apache/baremaps/server/GeocoderResource.java
b/baremaps-server/src/main/java/org/apache/baremaps/server/GeocoderResource.java
index 9b3543d8..75b237d5 100644
---
a/baremaps-server/src/main/java/org/apache/baremaps/server/GeocoderResource.java
+++
b/baremaps-server/src/main/java/org/apache/baremaps/server/GeocoderResource.java
@@ -75,8 +75,8 @@ public class GeocoderResource {
// population)
// - "paris brazil", returns paris in brazil and not paris in france.
var query = new GeonamesQueryBuilder()
-
.queryText(queryText).countryCode(countryCode).withScoringByPopulation()
- .withAndOperator()
+
.queryText(queryText).countryCode(countryCode).scoringByPopulation()
+ .andOperator()
.build();
var result = searcher.search(query, limit);
diff --git
a/baremaps-server/src/main/java/org/apache/baremaps/server/IpLocResource.java
b/baremaps-server/src/main/java/org/apache/baremaps/server/IpLocResource.java
index ab153e45..c137bbfd 100644
---
a/baremaps-server/src/main/java/org/apache/baremaps/server/IpLocResource.java
+++
b/baremaps-server/src/main/java/org/apache/baremaps/server/IpLocResource.java
@@ -100,22 +100,26 @@ public class IpLocResource {
}
public record InetnumLocationDto(
- String address,
+ String geocoderInput,
String inetStart,
String inetEnd,
double longitude,
double latitude,
String network,
- String country) {
+ String country,
+ String source,
+ String precision) {
public InetnumLocationDto(IpLocObject ipLocObject) {
- this(ipLocObject.address(),
+ this(ipLocObject.geocoderInput(),
ipLocObject.inetRange().start().toString().substring(1),
ipLocObject.inetRange().end().toString().substring(1),
ipLocObject.coordinate().getX(),
ipLocObject.coordinate().getY(),
ipLocObject.network(),
- ipLocObject.country());
+ ipLocObject.country(),
+ ipLocObject.source(),
+ ipLocObject.precision().toString());
}
}
}
diff --git a/baremaps-server/src/main/resources/iploc/index.html
b/baremaps-server/src/main/resources/iploc/index.html
index e4833a2c..b5ed834d 100644
--- a/baremaps-server/src/main/resources/iploc/index.html
+++ b/baremaps-server/src/main/resources/iploc/index.html
@@ -64,14 +64,14 @@
const table = document.getElementById('results');
table.innerHTML = '';
// Insert header row
- table.insertRow().innerHTML =
'<th>#</th><th>Address</th><th>IP
Range</th><th>Longitude</th><th>Latitude</th><th>Network</th><th>Country</th>';
+ table.insertRow().innerHTML =
'<th>#</th><th>GeocoderInput</th><th>IP
Range</th><th>Longitude</th><th>Latitude</th><th>Network</th><th>Country</th><th>Source</th><th>Precision</th>';
for (let i = 0; i < geoLocations.length; i++) {
const row = table.insertRow(i + 1);
let pos = 0;
let cell = row.insertCell(pos++);
cell.innerHTML = i + 1;
cell = row.insertCell(pos++);
- cell.innerHTML = geoLocations[i].address;
+ cell.innerHTML = geoLocations[i].geocoderInput;
cell = row.insertCell(pos++);
cell.innerHTML = `${geoLocations[i].inetStart} -
${geoLocations[i].inetEnd}`;
cell = row.insertCell(pos++);
@@ -82,6 +82,10 @@
cell.innerHTML = geoLocations[i].network;
cell = row.insertCell(pos++);
cell.innerHTML = geoLocations[i].country;
+ cell = row.insertCell(pos++);
+ cell.innerHTML = geoLocations[i].source;
+ cell = row.insertCell(pos++);
+ cell.innerHTML = geoLocations[i].precision;
}
} else {
// We reached our target server, but it returned an error
@@ -93,4 +97,4 @@
}
</script>
</body>
-</html>
\ No newline at end of file
+</html>