Skip to content

Commit 92375e5

Browse files
committed
update
1 parent bbeae1f commit 92375e5

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.nlpcn</groupId>
55
<artifactId>elasticsearch-sql</artifactId>
6-
<version>5.6.5.3</version>
6+
<version>5.6.5.4</version>
77
<packaging>jar</packaging>
88
<description>Query elasticsearch using SQL</description>
99
<name>elasticsearch-sql</name>

src/main/java/org/nlpcn/es4sql/domain/hints/HintFactory.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,20 @@ public static Hint getHintFromString(String hintAsString) throws SqlParseExcepti
141141
return new Hint(HintType.MINUS_USE_TERMS_OPTIMIZATION, new Object[]{shouldLowerStringOnTerms});
142142
}
143143
if (hintAsString.startsWith("! COLLAPSE")) {
144-
String[] collapses = getParamsFromHint(hintAsString, "! COLLAPSE");
145-
return new Hint(HintType.COLLAPSE, new String[]{"{" + String.join(",", collapses) + "}"});
144+
String collapse = getParamFromHint(hintAsString, "! COLLAPSE");
145+
return new Hint(HintType.COLLAPSE, new String[]{collapse});
146146
}
147147

148148
return null;
149149
}
150150

151-
151+
private static String getParamFromHint(String hint, String prefix) {
152+
if (!hint.contains("(")) return null;
153+
return hint.replace(prefix, "").replaceAll("\\s*\\(\\s*", "").replaceAll("\\s*\\,\\s*", ",").replaceAll("\\s*\\)\\s*", "");
154+
}
152155
private static String[] getParamsFromHint(String hint, String prefix) {
153-
if(!hint.contains("(")) return null;
154-
String onlyParams = hint.replace(prefix, "").replaceAll("\\s*\\(\\s*","").replaceAll("\\s*\\,\\s*", ",").replaceAll("\\s*\\)\\s*", "");
155-
return onlyParams.split(",");
156+
String param = getParamFromHint(hint, prefix);
157+
return param != null ? param.split(",") : null;
156158
}
157159
private static Integer[] parseParamsAsInts(String hintAsString,String startWith) {
158160
String[] number = getParamsFromHint(hintAsString,startWith);

src/test/java/org/nlpcn/es4sql/QueryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ public void highlightPreTagsAndPostTags() throws IOException, SqlParseException,
920920

921921
@Test
922922
public void fieldCollapsingTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
923-
String query = String.format("select /*! COLLAPSE(\"field\":\"age\",\"inner_hits\":{\"name\":\"account\",\"size\":1,\"sort\":[{\"age\":\"asc\"}]},\"max_concurrent_group_searches\": 4) */ * from %s/account", TEST_INDEX);
923+
String query = String.format("select /*! COLLAPSE({\"field\":\"age\",\"inner_hits\":{\"name\":\"account\",\"size\":1,\"sort\":[{\"age\":\"asc\"}]},\"max_concurrent_group_searches\": 4}) */ * from %s/account", TEST_INDEX);
924924
SearchHits hits = query(query);
925925
Assert.assertEquals(21, hits.getHits().length);
926926
}

0 commit comments

Comments
 (0)