Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making languages dynamic with command arguments #125

Merged
merged 24 commits into from
Dec 20, 2014
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ dependency-reduced-pom.xml
*.~*

__pycache__

nb-configuration.xml

nbactions.xml
227 changes: 1 addition & 226 deletions es/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,119 +47,34 @@
},
"city": {
"properties": {
"de": {
"type": "string",
"index": "no",
"copy_to": [
"collector.de"
]
},
"default": {
"type": "string",
"index": "no",
"copy_to": [
"collector.default"
]
},
"en": {
"type": "string",
"index": "no",
"copy_to": [
"collector.en"
]
},
"fr": {
"type": "string",
"index": "no",
"copy_to": [
"collector.fr"
]
},
"it": {
"type": "string",
"index": "no",
"copy_to": [
"collector.it"
]
}
}
},
"context": {
"properties": {
"de": {
"type": "string",
"index": "no",
"copy_to": [
"collector.default",
"collector.de"
]
},
"default": {
"type": "string",
"index": "no",
"copy_to": [
"collector.default"
]
},
"en": {
"type": "string",
"index": "no",
"copy_to": [
"collector.en"
]
},
"fr": {
"type": "string",
"index": "no",
"copy_to": [
"collector.fr"
]
},
"it": {
"type": "string",
"index": "no",
"copy_to": [
"collector.it"
]
}
}
},
"country": {
"properties": {
"de": {
"type": "string",
"index": "no",
"copy_to": [
"collector.de"
]
},
"default": {
"type": "string",
"index": "no",
"copy_to": [
"collector.default"
]
},
"en": {
"type": "string",
"index": "no",
"copy_to": [
"collector.en"
]
},
"fr": {
"type": "string",
"index": "no",
"copy_to": [
"collector.fr"
]
},
"it": {
"type": "string",
"index": "no",
"copy_to": [
"collector.it"
]
}
}
},
Expand Down Expand Up @@ -218,83 +133,11 @@
"collector.default"
]
},
"de": {
"type": "string",
"index": "no",
"fields": {
"ngrams": {
"type": "string",
"index_analyzer": "index_ngram"
},
"raw": {
"type": "string",
"index_analyzer": "index_raw"
}
},
"copy_to": [
"collector.de"
]
},
"default": {
"type": "string",
"index": "no",
"copy_to": [
"collector.default",
"name.en",
"name.de",
"name.fr",
"name.it"
]
},
"en": {
"type": "string",
"index": "no",
"fields": {
"ngrams": {
"type": "string",
"index_analyzer": "index_ngram"
},
"raw": {
"type": "string",
"index_analyzer": "index_raw"
}
},
"copy_to": [
"collector.en"
]
},
"fr": {
"type": "string",
"index": "no",
"fields": {
"ngrams": {
"type": "string",
"index_analyzer": "index_ngram"
},
"raw": {
"type": "string",
"index_analyzer": "index_raw"
}
},
"copy_to": [
"collector.fr"
]
},
"it": {
"type": "string",
"index": "no",
"fields": {
"ngrams": {
"type": "string",
"index_analyzer": "index_ngram"
},
"raw": {
"type": "string",
"index_analyzer": "index_raw"
}
},
"copy_to": [
"collector.it"
"collector.default"
]
}
}
Expand All @@ -308,34 +151,6 @@
"copy_to": [
"collector.default"
]
},
"de": {
"index": "no",
"type": "string",
"copy_to": [
"collector.de"
]
},
"en": {
"index": "no",
"type": "string",
"copy_to": [
"collector.en"
]
},
"fr": {
"index": "no",
"type": "string",
"copy_to": [
"collector.fr"
]
},
"it": {
"index": "no",
"type": "string",
"copy_to": [
"collector.it"
]
}
}
},
Expand All @@ -351,46 +166,6 @@
"analyzer": "index_raw"
}
}
},
"de": {
"type": "string",
"analyzer": "index_ngram",
"fields": {
"raw": {
"type": "string",
"analyzer": "index_raw"
}
}
},
"en": {
"type": "string",
"analyzer": "index_ngram",
"fields": {
"raw": {
"type": "string",
"analyzer": "index_raw"
}
}
},
"fr": {
"type": "string",
"analyzer": "index_ngram",
"fields": {
"raw": {
"type": "string",
"analyzer": "index_raw"
}
}
},
"it": {
"type": "string",
"analyzer": "index_ngram",
"fields": {
"raw": {
"type": "string",
"analyzer": "index_raw"
}
}
}
}
}
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/de/komoot/photon/importer/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void main(String[] rawArgs) {
if(args.getJsonDump() != null) {
try {
final String filename = args.getJsonDump();
final JsonDumper jsonDumper = new JsonDumper(filename);
final JsonDumper jsonDumper = new JsonDumper(filename, args.getUsingLanguages());
NominatimConnector nominatimConnector = new NominatimConnector(args.getHost(), args.getPort(), args.getDatabase(), args.getUser(), args.getPassword());
nominatimConnector.setImporter(jsonDumper);
nominatimConnector.readEntireDatabase();
Expand All @@ -52,7 +52,7 @@ public static void main(String[] rawArgs) {
}
}

final Server esServer = new Server(args.getCluster(), args.getDataDirectory());
final Server esServer = new Server(args.getCluster(), args.getDataDirectory(), args.getUsingLanguages());
esServer.start();

Client esNodeClient = esServer.getClient();
Expand All @@ -65,16 +65,22 @@ public static void main(String[] rawArgs) {

if(args.isNominatimImport()) {
esServer.recreateIndex(); // dump previous data
Importer importer = new Importer(esNodeClient);
log.info("starting import from nominatim to photon with languages: " + args.getUsingLanguages());
Importer importer = new Importer(esNodeClient, args.getUsingLanguages());
NominatimConnector nominatimConnector = new NominatimConnector(args.getHost(), args.getPort(), args.getDatabase(), args.getUser(), args.getPassword());
nominatimConnector.setImporter(importer);
nominatimConnector.readEntireDatabase();
log.info("imported data from nominatim to photon.");
try {
nominatimConnector.readEntireDatabase();
} catch (Exception e) {
log.info("ERROR IMPORTING FROM NOMINATIM: "+e.getMessage());
}

log.info("imported data from nominatim to photon with languages: " + args.getUsingLanguages());
return;
}

final NominatimUpdater nominatimUpdater = new NominatimUpdater(args.getHost(), args.getPort(), args.getDatabase(), args.getUser(), args.getPassword());
de.komoot.photon.importer.Updater updater = new de.komoot.photon.importer.elasticsearch.Updater(esNodeClient);
de.komoot.photon.importer.Updater updater = new de.komoot.photon.importer.elasticsearch.Updater(esNodeClient, args.getUsingLanguages());
nominatimUpdater.setUpdater(updater);

startApi(args, esNodeClient, nominatimUpdater);
Expand All @@ -99,7 +105,7 @@ public void run() {
});

final Searcher searcher = new Searcher(esNodeClient);
get(new RequestHandler("api", searcher));
get(new RequestHandler("api/", searcher));
get(new RequestHandler("api", searcher, args.getUsingLanguages()));
get(new RequestHandler("api/", searcher, args.getUsingLanguages()));
}
}
3 changes: 3 additions & 0 deletions src/main/java/de/komoot/photon/importer/CommandLineArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class CommandLineArgs {

@Parameter(names = "-nominatim-import", description = "import nominatim database into photon (this will delete previous index)")
private boolean nominatimImport = false;

@Parameter(names = "-using-languages", description = "languages nominatim importer should import and use at run-time, comma seperated (default: 'en,fr,de,it')")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just -languages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple and to the point, much better 👍

private String usingLanguages = "en,fr,de,it";

@Parameter(names = "-json", description = "import nominatim database and dump it to a json like files in (useful for developing)")
private String jsonDump = null;
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/de/komoot/photon/importer/RequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.google.common.base.Joiner;
import de.komoot.photon.importer.elasticsearch.Searcher;
import org.elasticsearch.common.collect.ImmutableSet;
import java.util.Arrays;
import java.util.HashSet;
import org.json.JSONArray;
import org.json.JSONObject;
import spark.Request;
Expand All @@ -19,11 +20,12 @@
*/
public class RequestHandler extends Route {
private final Searcher searcher;
private static final Set<String> supportedLanguages = ImmutableSet.of("de", "en", "fr", "it");

protected RequestHandler(String path, Searcher searcher) {
private final Set<String> supportedLanguages;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see spaces here, while the lines around have tabs, but I'm not sure what's the choice here. @christophlingg? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a formatting setting of the Netbeans config I use. I will change it to tabs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces still seem to be there ;)

protected RequestHandler(String path, Searcher searcher, String languages) {
super(path);
this.searcher = searcher;
this.supportedLanguages = new HashSet<String>(Arrays.asList(languages.split(",")));
}

@Override
Expand Down
Loading