Skip to content

Commit c796cbd

Browse files
authored
test: Add missing operator and edge case tests for AzureAiSearchFilterExpressionConverter (#4467)
Signed-off-by: Oleksandr Klymenko <[email protected]>
1 parent eac2e81 commit c796cbd

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

vector-stores/spring-ai-azure-store/src/test/java/org/springframework/ai/vectorstore/azure/AzureAiSearchFilterExpressionConverterTests.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3333
import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.AND;
3434
import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.EQ;
35+
import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.GT;
3536
import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.GTE;
3637
import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.IN;
38+
import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.LT;
3739
import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.LTE;
3840
import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.NE;
3941
import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.NIN;
@@ -185,4 +187,75 @@ public void testComplexIdentifiers() {
185187
assertThat(vectorExpr).isEqualTo(expected);
186188
}
187189

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+
188261
}

0 commit comments

Comments
 (0)