Skip to content

Commit f071a06

Browse files
authored
Merge pull request #799 from lonvia/port-to-opensearch
Add an experimental OpenSearch-based version
2 parents 447e0bd + c428004 commit f071a06

File tree

69 files changed

+2373
-272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2373
-272
lines changed

.github/workflows/ci.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
cache: 'gradle'
4646

4747
- name: Compile project
48-
run: ./gradlew assemble --no-daemon
48+
run: ./gradlew app:es_embedded:assemble --no-daemon
4949

5050
- uses: actions/checkout@v4
5151
with:
@@ -114,8 +114,9 @@ jobs:
114114

115115
- name: Import Photon
116116
run: |
117-
java -jar build/libs/photon-*.jar -nominatim-import -database nominatim -user runner -password foobar
118-
java -jar build/libs/photon-*.jar -nominatim-update-init-for runner -database nominatim -user runner -password foobar
117+
PHOTON_VERSION=`grep 'version =' buildSrc/shared.gradle | head -n 1 | sed "s:.*= '::;s:'.*::"`
118+
java -jar target/photon-${PHOTON_VERSION}.jar -nominatim-import -database nominatim -user runner -password foobar
119+
java -jar target/photon-${PHOTON_VERSION}.jar -nominatim-update-init-for runner -database nominatim -user runner -password foobar
119120
120121
- name: Update Nominatim
121122
run: |
@@ -128,4 +129,5 @@ jobs:
128129

129130
- name: Update Photon
130131
run: |
131-
java -jar build/libs/photon-*.jar -nominatim-update -database nominatim -user runner -password foobar
132+
PHOTON_VERSION=`grep 'version =' buildSrc/shared.gradle | head -n 1 | sed "s:.*= '::;s:'.*::"`
133+
java -jar target/photon-${PHOTON_VERSION}.jar -nominatim-update -database nominatim -user runner -password foobar

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
target/
22
photon_data/
33
dependency-reduced-pom.xml
4+
.gradle/
5+
app/*/build
46

57
.idea/
68
*.iml

README.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,26 @@ photon uses [gradle](https://gradle.org) for building. To build the package
5252
from source make sure you have a JDK installed. Then run:
5353

5454
```
55-
./gradlew build
55+
./gradlew app:es_embedded:build
5656
```
5757

58-
This will build and test photon. The final jar cn be found in `build/libs`.
58+
This will build and test photon. The final jar can be found in `target`.
59+
60+
#### Experimental OpenSearch version
61+
62+
The repository also contains a version that runs against the latest
63+
version of [OpenSearch](https://opensearch.org/). This version is still
64+
experimental. To build the OpenSearch version run:
65+
66+
```
67+
./gradlew app:opensearch:build
68+
```
69+
70+
The final jar can be found in `target/photon-opensearch-<VERSION>.jar`.
71+
72+
Indexes produced by this version are not compatible with the ElasticSearch
73+
version. There are no prebuilt indexes available. You need to create your
74+
own export from a Nominatim database. See 'Customized Search Data' below.
5975

6076
### Usage
6177

@@ -71,7 +87,7 @@ Check the URL `http://localhost:2322/api?q=berlin` to see if photon is running w
7187

7288
To enable CORS (cross-site requests), use `-cors-any` to allow any origin or `-cors-origin` with a specific origin as the argument. By default, CORS support is disabled.
7389

74-
Discover more of photon's featurse with its usage `java -jar photon-*.jar -h`. The available options are as follows:
90+
Discover more of photon's features with its usage `java -jar photon-*.jar -h`. The available options are as follows:
7591

7692
```
7793
-h Show help / usage

build.gradle app/es_embedded/build.gradle

+17-58
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,42 @@ plugins {
33
id 'application'
44
}
55

6-
group = 'de.komoot.photon'
7-
version = '0.5.0'
6+
apply from: rootProject.file('buildSrc/shared.gradle')
87

9-
description = "Geocoder for OSM data"
10-
11-
distZip.enabled = false
12-
distTar.enabled = false
13-
shadowDistZip.enabled = false
14-
shadowDistTar.enabled = false
15-
16-
application {
17-
mainClass = 'de.komoot.photon.App';
18-
}
19-
20-
java {
21-
sourceCompatibility = JavaVersion.VERSION_11
22-
targetCompatibility = JavaVersion.VERSION_11
23-
}
24-
25-
repositories {
26-
maven { url "https://www.datanucleus.org/downloads/maven2/" }
27-
mavenCentral()
28-
}
29-
30-
configurations {
31-
runtimePlugins.extendsFrom runtimeOnly {
32-
canBeResolved = true
33-
}
34-
}
8+
description = "Geocoder for OSM data (ElasticSearch-based version)"
359

3610
sourceSets {
3711
main {
3812
resources {
39-
srcDir 'build/es'
4013
srcDir 'es'
14+
srcDir 'build/es'
15+
}
16+
}
17+
test {
18+
java {
19+
srcDir 'src/test/java'
4120
}
4221
}
4322
}
4423

45-
dependencies {
46-
implementation('org.elasticsearch:elasticsearch:5.6.16') {
47-
exclude(module: 'log4j-api')
24+
configurations {
25+
runtimePlugins.extendsFrom runtimeOnly {
26+
canBeResolved = true
4827
}
28+
}
29+
30+
dependencies {
31+
implementation 'org.elasticsearch:elasticsearch:5.6.16'
4932
implementation 'org.elasticsearch.plugin:transport-netty4-client:5.6.16'
50-
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
51-
implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
5233
implementation('org.elasticsearch.client:transport:5.6.16') {
5334
exclude(module: 'commons-logging')
5435
}
55-
implementation 'org.postgresql:postgresql:42.7.2'
56-
implementation 'org.slf4j:slf4j-api:2.0.13'
57-
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1'
58-
implementation 'com.beust:jcommander:1.82'
59-
implementation 'org.apache.commons:commons-lang3:3.14.0'
60-
implementation 'org.springframework:spring-jdbc:5.3.32'
61-
implementation('org.apache.commons:commons-dbcp2:2.12.0') {
62-
exclude(module: 'commons-logging')
63-
}
64-
implementation 'org.locationtech.jts:jts-core:1.19.0'
65-
implementation 'com.sparkjava:spark-core:2.9.4'
66-
implementation 'net.postgis:postgis-jdbc:2023.1.0'
67-
implementation 'org.json:json:20240303'
68-
69-
testImplementation(platform("org.junit:junit-bom:5.10.2"))
70-
testImplementation 'com.h2database:h2:2.2.224'
71-
testImplementation 'org.junit.jupiter:junit-jupiter'
72-
testImplementation 'org.mockito:mockito-core:5.11.0'
73-
74-
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
7536

7637
runtimePlugins 'org.codelibs.elasticsearch.module:lang-painless:5.6.16'
7738
runtimePlugins 'org.ow2.asm:asm-debug-all:5.1'
7839
runtimePlugins 'org.antlr:antlr4-runtime:4.5.1-1'
7940
}
8041

81-
tasks.named('test') {
82-
useJUnitPlatform()
83-
}
84-
8542
task copyLibs(type: Copy){
8643
from configurations.runtimePlugins {
8744
into layout.buildDirectory.dir('es/modules/lang-painless')
@@ -100,6 +57,8 @@ tasks.named('processResources') {
10057

10158
shadowJar {
10259
mergeServiceFiles()
60+
destinationDirectory.set(rootProject.file('target'))
61+
archiveBaseName.set('photon')
10362
archiveClassifier.set('')
10463

10564
exclude '**/module-info.class'
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/main/java/de/komoot/photon/JsonDumper.java app/es_embedded/src/main/java/de/komoot/photon/JsonDumper.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.komoot.photon;
22

3+
import de.komoot.photon.elasticsearch.PhotonDocConverter;
34
import org.slf4j.Logger;
45

56
import java.io.FileNotFoundException;
@@ -26,7 +27,7 @@ public JsonDumper(String filename, String[] languages, String[] extraTags) throw
2627
public void add(PhotonDoc doc, int objectId) {
2728
try {
2829
writer.println("{\"index\": {}}");
29-
writer.println(Utils.convert(doc, languages, extraTags).string());
30+
writer.println(PhotonDocConverter.convert(doc, languages, extraTags).string());
3031
} catch (IOException e) {
3132
LOGGER.error("Error writing json file", e);
3233
}

src/main/java/de/komoot/photon/elasticsearch/Server.java app/es_embedded/src/main/java/de/komoot/photon/Server.java

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package de.komoot.photon.elasticsearch;
1+
package de.komoot.photon;
22

33
import de.komoot.photon.DatabaseProperties;
44
import de.komoot.photon.Importer;
55
import de.komoot.photon.Updater;
66
import de.komoot.photon.searcher.ReverseHandler;
77
import de.komoot.photon.searcher.SearchHandler;
8+
import de.komoot.photon.elasticsearch.*;
89
import org.elasticsearch.action.get.GetResponse;
910
import org.elasticsearch.client.Client;
1011
import org.elasticsearch.client.transport.TransportClient;
@@ -40,16 +41,6 @@
4041
public class Server {
4142
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(Server.class);
4243

43-
/**
44-
* Database version created by new imports with the current code.
45-
*
46-
* Format must be: major.minor.patch-dev
47-
*
48-
* Increase to next to be released version when the database layout
49-
* changes in an incompatible way. If it is already at the next released
50-
* version, increase the dev version.
51-
*/
52-
private static final String DATABASE_VERSION = "0.3.6-1";
5344
public static final String PROPERTY_DOCUMENT_ID = "DATABASE_PROPERTIES";
5445

5546
private static final String BASE_FIELD = "document_properties";
@@ -231,7 +222,7 @@ private void deleteIndex() {
231222
*/
232223
public void saveToDatabase(DatabaseProperties dbProperties) throws IOException {
233224
final XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject(BASE_FIELD)
234-
.field(FIELD_VERSION, DATABASE_VERSION)
225+
.field(FIELD_VERSION, DatabaseProperties.DATABASE_VERSION)
235226
.field(FIELD_LANGUAGES, String.join(",", dbProperties.getLanguages()))
236227
.field(FIELD_IMPORT_DATE, dbProperties.getImportDate() instanceof Date ? dbProperties.getImportDate().toInstant() : null)
237228
.endObject().endObject();
@@ -264,8 +255,8 @@ public void loadFromDatabase(DatabaseProperties dbProperties) {
264255
}
265256

266257
String version = properties.getOrDefault(FIELD_VERSION, "");
267-
if (!DATABASE_VERSION.equals(version)) {
268-
LOGGER.error("Database has incompatible version '{}'. Expected: {}", version, DATABASE_VERSION);
258+
if (!DatabaseProperties.DATABASE_VERSION.equals(version)) {
259+
LOGGER.error("Database has incompatible version '{}'. Expected: {}", version, DatabaseProperties.DATABASE_VERSION);
269260
throw new RuntimeException("Incompatible database.");
270261
}
271262

src/main/java/de/komoot/photon/elasticsearch/Importer.java app/es_embedded/src/main/java/de/komoot/photon/elasticsearch/Importer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void add(PhotonDoc doc, int objectId) {
3434
String uid = doc.getUid(objectId);
3535
try {
3636
this.bulkRequest.add(this.esClient.prepareIndex(PhotonIndex.NAME, PhotonIndex.TYPE).
37-
setSource(Utils.convert(doc, languages, extraTags)).setId(uid));
37+
setSource(PhotonDocConverter.convert(doc, languages, extraTags)).setId(uid));
3838
} catch (IOException e) {
3939
LOGGER.error("Could not bulk add document {}", uid, e);
4040
return;

0 commit comments

Comments
 (0)