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

fix search query mutiple sort option #1799

Merged
Merged
Changes from all 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
fix search query mutiple sort option
Signed-off-by: Aleksandar Stanchev <aleksandar.stanchev@bosch.com>
alstanchev committed Nov 8, 2023
commit a5c98aa0411b3c330e1501c9c2cf7fdb3c86034a
Original file line number Diff line number Diff line change
@@ -206,7 +206,8 @@ public static List<String> calculateOptions(final List<String> optionsString) {
}
return optionsString
.stream()
.flatMap(s -> Arrays.stream(s.split(",")))
.flatMap(s -> Arrays.stream(s.split("\\),")))
.map(s -> s.endsWith(")") ? s : s + ")")
.toList();
}

Original file line number Diff line number Diff line change
@@ -49,15 +49,28 @@ public void postSearchThingsShouldGetParametersFromBody() {
final var formData = FormData.create(
List.of(
new Pair<>("filter", "and(like(definition,\"*test*\"))"),
new Pair<>("option", "sort(+thingId)"),
new Pair<>("option", "sort(+thingId,-attributes/type)"),
new Pair<>("option","limit(0,5)"),
new Pair<>("namespaces","org.eclipse.ditto,foo.bar")
));
final var result = underTest.run(HttpRequest.POST("/search/things")
.withEntity(formData.toEntity()));

result.assertStatusCode(StatusCodes.OK);
result.assertEntity("{\"type\":\"thing-search.commands:queryThings\",\"filter\":\"and(and(like(definition,\\\"*test*\\\")))\",\"options\":[\"limit(0\",\"5)\",\"sort(+thingId)\"],\"namespaces\":[\"foo.bar\",\"org.eclipse.ditto\"]}");
result.assertEntity("{\"type\":\"thing-search.commands:queryThings\",\"filter\":\"and(and(like(definition,\\\"*test*\\\")))\",\"options\":[\"limit(0,5)\",\"sort(+thingId,-attributes/type)\"],\"namespaces\":[\"foo.bar\",\"org.eclipse.ditto\"]}");
}
@Test
public void searchThingsShouldGetParametersFromUrl() {

final var result = underTest.run(HttpRequest.GET(
"/search/things?" +
"namespaces=org.eclipse.ditto&" +
"fields=thingId&" +
"option=sort(%2Bfeature/property,-attributes/type,%2BthingId),size(2),cursor(nextCursor)")
);

result.assertStatusCode(StatusCodes.OK);
result.assertEntity("{\"type\":\"thing-search.commands:queryThings\",\"options\":[\"sort(+feature/property,-attributes/type,+thingId)\",\"size(2)\",\"cursor(nextCursor)\"],\"fields\":\"/thingId\",\"namespaces\":[\"org.eclipse.ditto\"]}");
}

@Test