Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ private String getOperationSymbol(Filter.Expression exp) {
}

@Override
protected void doGroup(Filter.Group group, StringBuilder context) {
this.convertOperand(new Filter.Expression(Filter.ExpressionType.AND, group.content(), group.content()),
context); // trick
protected void doStartGroup(Filter.Group group, StringBuilder context) {
context.append("(");
}

@Override
protected void doEndGroup(Filter.Group group, StringBuilder context) {
context.append(")");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.api.Test;

import org.springframework.ai.vectorstore.filter.Filter.Expression;
import org.springframework.ai.vectorstore.filter.Filter.Group;
import org.springframework.ai.vectorstore.filter.Filter.Key;
import org.springframework.ai.vectorstore.filter.Filter.Value;
import org.springframework.ai.vectorstore.filter.FilterExpressionConverter;
Expand Down Expand Up @@ -105,6 +106,17 @@ void testOr() {
assertThat(vectorExpr).isEqualTo("metadata.country: \"BG\" || metadata.country: \"NL\"");
}

@Test
void testGroupAsRightOperand() {
// city == "Sofia" AND (year >= 2020 OR country == "BG")
String vectorExpr = this.converter
.convertExpression(new Expression(AND, new Expression(EQ, new Key("city"), new Value("Sofia")),
new Group(new Expression(OR, new Expression(GTE, new Key("year"), new Value(2020)),
new Expression(EQ, new Key("country"), new Value("BG"))))));
assertThat(vectorExpr).isEqualTo(
"metadata.city: \"Sofia\" && (metadata.year: >= 2020 || metadata.country: \"BG\")");
}

@Test
void testBoolean() {
String vectorExpr = this.converter
Expand Down