|
32 | 32 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
33 | 33 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.AND; |
34 | 34 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.EQ; |
| 35 | +import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.GT; |
35 | 36 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.GTE; |
36 | 37 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.IN; |
| 38 | +import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.LT; |
37 | 39 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.LTE; |
38 | 40 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.NE; |
39 | 41 | import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.NIN; |
@@ -185,4 +187,75 @@ public void testComplexIdentifiers() { |
185 | 187 | assertThat(vectorExpr).isEqualTo(expected); |
186 | 188 | } |
187 | 189 |
|
| 190 | + @Test |
| 191 | + public void testNullValue() { |
| 192 | + FilterExpressionConverter converter = new AzureAiSearchFilterExpressionConverter( |
| 193 | + List.of(MetadataField.text("value1"))); |
| 194 | + |
| 195 | + // value1 == null |
| 196 | + String expected = "meta_value1 eq null"; |
| 197 | + String vectorExpr = converter.convertExpression(new Expression(EQ, new Key("value1"), new Value(null))); |
| 198 | + assertThat(vectorExpr).isEqualTo(expected); |
| 199 | + } |
| 200 | + |
| 201 | + @Test |
| 202 | + public void testEmptyStringValue() { |
| 203 | + FilterExpressionConverter converter = new AzureAiSearchFilterExpressionConverter( |
| 204 | + List.of(MetadataField.text("field1"))); |
| 205 | + |
| 206 | + // field1 == "" |
| 207 | + String expected = "meta_field1 eq ''"; |
| 208 | + String vectorExpr = converter.convertExpression(new Expression(EQ, new Key("field1"), new Value(""))); |
| 209 | + assertThat(vectorExpr).isEqualTo(expected); |
| 210 | + } |
| 211 | + |
| 212 | + @Test |
| 213 | + public void testGtAndLt() { |
| 214 | + FilterExpressionConverter converter = new AzureAiSearchFilterExpressionConverter( |
| 215 | + List.of(MetadataField.int32("number1"))); |
| 216 | + |
| 217 | + // number1 > 100 |
| 218 | + String expected = "meta_number1 gt 100"; |
| 219 | + String vectorExpr = converter.convertExpression(new Expression(GT, new Key("number1"), new Value(100))); |
| 220 | + assertThat(vectorExpr).isEqualTo(expected); |
| 221 | + |
| 222 | + // number1 < 500 |
| 223 | + expected = "meta_number1 lt 500"; |
| 224 | + vectorExpr = converter.convertExpression(new Expression(LT, new Key("number1"), new Value(500))); |
| 225 | + assertThat(vectorExpr).isEqualTo(expected); |
| 226 | + } |
| 227 | + |
| 228 | + @Test |
| 229 | + public void testNestedGroups() { |
| 230 | + FilterExpressionConverter converter = new AzureAiSearchFilterExpressionConverter( |
| 231 | + List.of(MetadataField.text("type1"), MetadataField.int32("value1"), MetadataField.text("code1"), |
| 232 | + MetadataField.bool("flag1"))); |
| 233 | + |
| 234 | + // ((type1 == "alpha" AND value1 <= 1000) OR (code1 == "beta")) AND flag1 == true |
| 235 | + String expected = "((meta_type1 eq 'alpha' and meta_value1 le 1000) or meta_code1 eq 'beta') and meta_flag1 eq true"; |
| 236 | + String vectorExpr = converter.convertExpression(new Expression(AND, |
| 237 | + new Group(new Expression(OR, |
| 238 | + new Group(new Expression(AND, new Expression(EQ, new Key("type1"), new Value("alpha")), |
| 239 | + new Expression(LTE, new Key("value1"), new Value(1000)))), |
| 240 | + new Expression(EQ, new Key("code1"), new Value("beta")))), |
| 241 | + new Expression(EQ, new Key("flag1"), new Value(true)))); |
| 242 | + assertThat(vectorExpr).isEqualTo(expected); |
| 243 | + } |
| 244 | + |
| 245 | + @Test |
| 246 | + public void testCaseSensitiveFieldNames() { |
| 247 | + FilterExpressionConverter converter = new AzureAiSearchFilterExpressionConverter( |
| 248 | + List.of(MetadataField.text("ConfigValue"), MetadataField.text("configvalue"))); |
| 249 | + |
| 250 | + // ConfigValue == "data1" |
| 251 | + String expected = "meta_ConfigValue eq 'data1'"; |
| 252 | + String vectorExpr = converter.convertExpression(new Expression(EQ, new Key("ConfigValue"), new Value("data1"))); |
| 253 | + assertThat(vectorExpr).isEqualTo(expected); |
| 254 | + |
| 255 | + // configvalue == "data2" |
| 256 | + expected = "meta_configvalue eq 'data2'"; |
| 257 | + vectorExpr = converter.convertExpression(new Expression(EQ, new Key("configvalue"), new Value("data2"))); |
| 258 | + assertThat(vectorExpr).isEqualTo(expected); |
| 259 | + } |
| 260 | + |
188 | 261 | } |
0 commit comments