| 
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;  | 
@@ -119,4 +121,126 @@ public void testComplexIdentifiers() {  | 
119 | 121 | 		assertThat(vectorExpr).isEqualTo("$.\"country 1 2 3\" == \"BG\"");  | 
120 | 122 | 	}  | 
121 | 123 | 
 
  | 
 | 124 | +	@Test  | 
 | 125 | +	public void testLT() {  | 
 | 126 | +		// value < 100  | 
 | 127 | +		String vectorExpr = this.converter.convertExpression(new Expression(LT, new Key("value"), new Value(100)));  | 
 | 128 | +		assertThat(vectorExpr).isEqualTo("$.value < 100");  | 
 | 129 | +	}  | 
 | 130 | + | 
 | 131 | +	@Test  | 
 | 132 | +	public void testGT() {  | 
 | 133 | +		// score > 75  | 
 | 134 | +		String vectorExpr = this.converter.convertExpression(new Expression(GT, new Key("score"), new Value(100)));  | 
 | 135 | +		assertThat(vectorExpr).isEqualTo("$.score > 100");  | 
 | 136 | +	}  | 
 | 137 | + | 
 | 138 | +	@Test  | 
 | 139 | +	public void testLTE() {  | 
 | 140 | +		// amount <= 100.5  | 
 | 141 | +		String vectorExpr = this.converter.convertExpression(new Expression(LTE, new Key("amount"), new Value(100.5)));  | 
 | 142 | +		assertThat(vectorExpr).isEqualTo("$.amount <= 100.5");  | 
 | 143 | +	}  | 
 | 144 | + | 
 | 145 | +	@Test  | 
 | 146 | +	public void testNIN() {  | 
 | 147 | +		// category NOT IN ["typeA", "typeB"]  | 
 | 148 | +		String vectorExpr = this.converter  | 
 | 149 | +			.convertExpression(new Expression(NIN, new Key("category"), new Value(List.of("typeA", "typeB"))));  | 
 | 150 | +		assertThat(vectorExpr).isEqualTo("!($.category == \"typeA\" || $.category == \"typeB\")");  | 
 | 151 | +	}  | 
 | 152 | + | 
 | 153 | +	@Test  | 
 | 154 | +	public void testSingleValueIN() {  | 
 | 155 | +		// status IN ["active"] - single value in list  | 
 | 156 | +		String vectorExpr = this.converter  | 
 | 157 | +			.convertExpression(new Expression(IN, new Key("status"), new Value(List.of("active"))));  | 
 | 158 | +		assertThat(vectorExpr).isEqualTo("($.status == \"active\")");  | 
 | 159 | +	}  | 
 | 160 | + | 
 | 161 | +	@Test  | 
 | 162 | +	public void testSingleValueNIN() {  | 
 | 163 | +		// status NOT IN ["inactive"] - single value in list  | 
 | 164 | +		String vectorExpr = this.converter  | 
 | 165 | +			.convertExpression(new Expression(NIN, new Key("status"), new Value(List.of("inactive"))));  | 
 | 166 | +		assertThat(vectorExpr).isEqualTo("!($.status == \"inactive\")");  | 
 | 167 | +	}  | 
 | 168 | + | 
 | 169 | +	@Test  | 
 | 170 | +	public void testNumericIN() {  | 
 | 171 | +		// priority IN [1, 2, 3]  | 
 | 172 | +		String vectorExpr = this.converter  | 
 | 173 | +			.convertExpression(new Expression(IN, new Key("priority"), new Value(List.of(1, 2, 3))));  | 
 | 174 | +		assertThat(vectorExpr).isEqualTo("($.priority == 1 || $.priority == 2 || $.priority == 3)");  | 
 | 175 | +	}  | 
 | 176 | + | 
 | 177 | +	@Test  | 
 | 178 | +	public void testNumericNIN() {  | 
 | 179 | +		// level NOT IN [0, 10]  | 
 | 180 | +		String vectorExpr = this.converter  | 
 | 181 | +			.convertExpression(new Expression(NIN, new Key("level"), new Value(List.of(0, 10))));  | 
 | 182 | +		assertThat(vectorExpr).isEqualTo("!($.level == 0 || $.level == 10)");  | 
 | 183 | +	}  | 
 | 184 | + | 
 | 185 | +	@Test  | 
 | 186 | +	public void testNestedGroups() {  | 
 | 187 | +		// ((score >= 80 AND type == "A") OR (score >= 90 AND type == "B")) AND status ==  | 
 | 188 | +		// "valid"  | 
 | 189 | +		String vectorExpr = this.converter.convertExpression(new Expression(AND,  | 
 | 190 | +				new Group(new Expression(OR,  | 
 | 191 | +						new Group(new Expression(AND, new Expression(GTE, new Key("score"), new Value(80)),  | 
 | 192 | +								new Expression(EQ, new Key("type"), new Value("A")))),  | 
 | 193 | +						new Group(new Expression(AND, new Expression(GTE, new Key("score"), new Value(90)),  | 
 | 194 | +								new Expression(EQ, new Key("type"), new Value("B")))))),  | 
 | 195 | +				new Expression(EQ, new Key("status"), new Value("valid"))));  | 
 | 196 | +		assertThat(vectorExpr).isEqualTo(  | 
 | 197 | +				"(($.score >= 80 && $.type == \"A\") || ($.score >= 90 && $.type == \"B\")) && $.status == \"valid\"");  | 
 | 198 | +	}  | 
 | 199 | + | 
 | 200 | +	@Test  | 
 | 201 | +	public void testBooleanFalse() {  | 
 | 202 | +		// active == false  | 
 | 203 | +		String vectorExpr = this.converter.convertExpression(new Expression(EQ, new Key("active"), new Value(false)));  | 
 | 204 | +		assertThat(vectorExpr).isEqualTo("$.active == false");  | 
 | 205 | +	}  | 
 | 206 | + | 
 | 207 | +	@Test  | 
 | 208 | +	public void testBooleanNE() {  | 
 | 209 | +		// active != true  | 
 | 210 | +		String vectorExpr = this.converter.convertExpression(new Expression(NE, new Key("active"), new Value(true)));  | 
 | 211 | +		assertThat(vectorExpr).isEqualTo("$.active != true");  | 
 | 212 | +	}  | 
 | 213 | + | 
 | 214 | +	@Test  | 
 | 215 | +	public void testKeyWithDots() {  | 
 | 216 | +		// "config.setting" == "value1"  | 
 | 217 | +		String vectorExpr = this.converter  | 
 | 218 | +			.convertExpression(new Expression(EQ, new Key("\"config.setting\""), new Value("value1")));  | 
 | 219 | +		assertThat(vectorExpr).isEqualTo("$.\"config.setting\" == \"value1\"");  | 
 | 220 | +	}  | 
 | 221 | + | 
 | 222 | +	@Test  | 
 | 223 | +	public void testEmptyString() {  | 
 | 224 | +		// description == ""  | 
 | 225 | +		String vectorExpr = this.converter.convertExpression(new Expression(EQ, new Key("description"), new Value("")));  | 
 | 226 | +		assertThat(vectorExpr).isEqualTo("$.description == \"\"");  | 
 | 227 | +	}  | 
 | 228 | + | 
 | 229 | +	@Test  | 
 | 230 | +	public void testNullValue() {  | 
 | 231 | +		// metadata == null  | 
 | 232 | +		String vectorExpr = this.converter.convertExpression(new Expression(EQ, new Key("metadata"), new Value(null)));  | 
 | 233 | +		assertThat(vectorExpr).isEqualTo("$.metadata == null");  | 
 | 234 | +	}  | 
 | 235 | + | 
 | 236 | +	@Test  | 
 | 237 | +	public void testComplexOrExpression() {  | 
 | 238 | +		// state == "ready" OR state == "pending" OR state == "processing"  | 
 | 239 | +		String vectorExpr = this.converter.convertExpression(new Expression(OR,  | 
 | 240 | +				new Expression(OR, new Expression(EQ, new Key("state"), new Value("ready")),  | 
 | 241 | +						new Expression(EQ, new Key("state"), new Value("pending"))),  | 
 | 242 | +				new Expression(EQ, new Key("state"), new Value("processing"))));  | 
 | 243 | +		assertThat(vectorExpr).isEqualTo("$.state == \"ready\" || $.state == \"pending\" || $.state == \"processing\"");  | 
 | 244 | +	}  | 
 | 245 | + | 
122 | 246 | }  | 
0 commit comments