|
29 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
30 | 30 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.AND; |
31 | 31 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.EQ; |
| 32 | +import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.GT; |
32 | 33 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.GTE; |
33 | 34 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.IN; |
| 35 | +import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.LT; |
34 | 36 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.LTE; |
35 | 37 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.NE; |
36 | 38 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.NIN; |
@@ -86,11 +88,11 @@ public void testGroup() { |
86 | 88 | new Expression(EQ, new Key("country"), new Value("BG")))), |
87 | 89 | new Expression(NIN, new Key("city"), new Value(List.of("Sofia", "Plovdiv"))))); |
88 | 90 | assertThat(vectorExpr).isEqualTo( |
89 | | - "metadata[\"year\"] >= 2020 || metadata[\"country\"] == \"BG\" && metadata[\"year\"] >= 2020 || metadata[\"country\"] == \"BG\" && metadata[\"city\"] nin [\"Sofia\",\"Plovdiv\"]"); |
| 91 | + "metadata[\"year\"] >= 2020 || metadata[\"country\"] == \"BG\" && metadata[\"year\"] >= 2020 || metadata[\"country\"] == \"BG\" && metadata[\"city\"] not in [\"Sofia\",\"Plovdiv\"]"); |
90 | 92 | } |
91 | 93 |
|
92 | 94 | @Test |
93 | | - public void tesBoolean() { |
| 95 | + public void testBoolean() { |
94 | 96 | // isOpen == true AND year >= 2020 AND country IN ["BG", "NL", "US"] |
95 | 97 | String vectorExpr = this.converter.convertExpression(new Expression(AND, |
96 | 98 | new Expression(AND, new Expression(EQ, new Key("isOpen"), new Value(true)), |
@@ -121,4 +123,36 @@ public void testComplexIdentifiers() { |
121 | 123 | assertThat(vectorExpr).isEqualTo("metadata[\"country 1 2 3\"] == \"BG\""); |
122 | 124 | } |
123 | 125 |
|
| 126 | + @Test |
| 127 | + public void testLt() { |
| 128 | + // temperature < 0 |
| 129 | + String vectorExpr = this.converter.convertExpression(new Expression(LT, new Key("temperature"), new Value(0))); |
| 130 | + assertThat(vectorExpr).isEqualTo("metadata[\"temperature\"] < 0"); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + public void testLte() { |
| 135 | + // humidity <= 100 |
| 136 | + String vectorExpr = this.converter.convertExpression(new Expression(LTE, new Key("humidity"), new Value(100))); |
| 137 | + assertThat(vectorExpr).isEqualTo("metadata[\"humidity\"] <= 100"); |
| 138 | + } |
| 139 | + |
| 140 | + @Test |
| 141 | + public void testGt() { |
| 142 | + // price > 1000 |
| 143 | + String vectorExpr = this.converter.convertExpression(new Expression(GT, new Key("price"), new Value(1000))); |
| 144 | + assertThat(vectorExpr).isEqualTo("metadata[\"price\"] > 1000"); |
| 145 | + } |
| 146 | + |
| 147 | + @Test |
| 148 | + public void testCombinedComparisons() { |
| 149 | + // price > 1000 && temperature < 25 && humidity <= 80 |
| 150 | + String vectorExpr = this.converter.convertExpression(new Expression(AND, |
| 151 | + new Expression(AND, new Expression(GT, new Key("price"), new Value(1000)), |
| 152 | + new Expression(LT, new Key("temperature"), new Value(25))), |
| 153 | + new Expression(LTE, new Key("humidity"), new Value(80)))); |
| 154 | + assertThat(vectorExpr) |
| 155 | + .isEqualTo("metadata[\"price\"] > 1000 && metadata[\"temperature\"] < 25 && metadata[\"humidity\"] <= 80"); |
| 156 | + } |
| 157 | + |
124 | 158 | } |
0 commit comments