Skip to content

Commit b027c5a

Browse files
committed
[NAE-2460] PFQL placeholder support
- update QueryLangEvaluator to aim for fulltextValue elasticsearch attribute
1 parent 088f68e commit b027c5a

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,11 @@ public void exitDataString(QueryLangParser.DataStringContext ctx) {
12151215
String string = handleStringComparisonWithPlaceholders(ctx.stringComparison());
12161216

12171217
setMongoQuery(ctx, null);
1218-
setElasticQuery(ctx, buildElasticQuery("dataSet." + fieldId + ".textValue", op.getType(), string, not));
1218+
String attribute = "dataSet." + fieldId + ".fulltextValue";
1219+
if (op.getType() == QueryLangParser.EQ || op.getType() == QueryLangParser.NEQ) {
1220+
attribute += ".keyword";
1221+
}
1222+
setElasticQuery(ctx, buildElasticQuery(attribute, op.getType(), string, not));
12191223
this.searchWithElastic = true;
12201224
}
12211225

@@ -1226,7 +1230,7 @@ public void exitDataStringList(QueryLangParser.DataStringListContext ctx) {
12261230
List<String> stringList = handleStringListComparison(ctx.inListStringComparison().stringList());
12271231

12281232
setMongoQuery(ctx, null);
1229-
setElasticQuery(ctx, buildElasticQueryInList("dataSet." + fieldId + ".textValue", stringList, not));
1233+
setElasticQuery(ctx, buildElasticQueryInList("dataSet." + fieldId + ".fulltextValue", stringList, not));
12301234
this.searchWithElastic = true;
12311235
}
12321236

@@ -1239,7 +1243,7 @@ public void exitDataStringRange(QueryLangParser.DataStringRangeContext ctx) {
12391243
Pair<String, String> leftAndRightStrings = handleInRangeStringComparison(ctx.inRangeStringComparison().stringRange());
12401244

12411245
setMongoQuery(ctx, null);
1242-
setElasticQuery(ctx, buildElasticQueryInRange("dataSet." + fieldId + ".textValue", leftAndRightStrings.getFirst(),
1246+
setElasticQuery(ctx, buildElasticQueryInRange("dataSet." + fieldId + ".fulltextValue", leftAndRightStrings.getFirst(),
12431247
leftEndpointOpen, leftAndRightStrings.getSecond(), rightEndpointOpen, not));
12441248
this.searchWithElastic = true;
12451249
}

src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ public void testSimpleElasticCaseQuery() {
10111011
assertEquals(expected, actual);
10121012

10131013
// data value comparison
1014-
checkStringComparisonElastic("case", "data.field1.value", "dataSet.field1.textValue");
1014+
checkStringComparisonElastic("case", "data.field1.value", "dataSet.field1.fulltextValue");
10151015

10161016
checkNumberComparisonElastic("case", "data.field2.value", "dataSet.field2.numberValue");
10171017

@@ -2034,7 +2034,12 @@ private static void checkDateComparison(MongoDbUtils<?> mongoDbUtils, String res
20342034

20352035
private static void checkStringComparisonElastic(String resource, String attribute, String resultAttribute) {
20362036
String actual = evaluateQuery(String.format("%s: %s eq 'test'", resource, attribute)).getFullElasticQuery();
2037-
String expected = String.format("%s:test", resultAttribute);
2037+
String expected;
2038+
if (resultAttribute.matches("dataSet\\.[^.]*\\.fulltextValue")) {
2039+
expected = String.format("%s.keyword:test", resultAttribute);
2040+
} else {
2041+
expected = String.format("%s:test", resultAttribute);
2042+
}
20382043

20392044
assertEquals(expected, actual);
20402045

0 commit comments

Comments
 (0)