Skip to content

Commit

Permalink
[ issue #95 ] Template/Default template Fix in EE/OSS integration
Browse files Browse the repository at this point in the history
(cherry picked from commit 5e2d1f9)
  • Loading branch information
agazzarini committed Nov 15, 2019
1 parent cb580b8 commit 914269d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,19 @@ void completeQuery(Query query) {
* A query string is the result of replacing all placeholders found in the template.
*
* @param queryNode the JSON query node (in ratings configuration).
* @param template the default template that will be used if a query doesn't declare it.
* @param defaultTemplate the default template that will be used if a query doesn't declare it.
* @param version the version being executed.
* @return a query (as a string) that will be used for executing a specific evaluation.
*/
private String query(final JsonNode queryNode, final String template, final String version) {
private String query(final JsonNode queryNode, final String defaultTemplate, final String version) {
// try to see if the query declares a template
String template = getQueryTemplate(queryNode).orElse(null);
try {
if (template == null) {
// EE case
if (template == null && defaultTemplate == null) {
return queryNode.toString();
} else {
String query = templateManager.getTemplate(template, getQueryTemplate(queryNode).orElse(null), version);
String query = templateManager.getTemplate(defaultTemplate, template, version);
for (final Iterator<String> iterator = queryNode.get("placeholders").fieldNames(); iterator.hasNext(); ) {
final String name = iterator.next();
query = query.replace(name, queryNode.get("placeholders").get(name).asText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public QueryOrSearchResponse executeQuery(final String indexName, final String q
} catch (final ElasticsearchException e) {
LOGGER.error("Caught ElasticsearchException :: " + e.getMessage());
return new QueryOrSearchResponse(0, Collections.emptyList());
} catch (final IOException exception) {
} catch (final Exception exception) {
throw new RuntimeException(exception);
}
}
Expand Down

0 comments on commit 914269d

Please sign in to comment.