File tree 1 file changed +15
-1
lines changed
spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 24
24
import org .springframework .ai .vectorstore .filter .FilterExpressionTextParser ;
25
25
import org .springframework .lang .Nullable ;
26
26
import org .springframework .util .Assert ;
27
+ import java .util .regex .Pattern ;
28
+ import java .util .regex .Matcher ;
27
29
28
30
/**
29
31
* Similarity search request. Use the {@link SearchRequest#builder()} to create the
@@ -283,10 +285,22 @@ public Builder filterExpression(@Nullable Filter.Expression expression) {
283
285
*/
284
286
public Builder filterExpression (@ Nullable String textExpression ) {
285
287
this .searchRequest .filterExpression = (textExpression != null )
286
- ? new FilterExpressionTextParser ().parse (textExpression ) : null ;
288
+ ? new FilterExpressionTextParser ().parse (escapeTextExpression ( textExpression ) ) : null ;
287
289
return this ;
288
290
}
289
291
292
+ private String escapeTextExpression (String expression ) {
293
+ Pattern pattern = Pattern .compile ("'([^']*)'" );
294
+ Matcher matcher = pattern .matcher (expression );
295
+ StringBuffer sb = new StringBuffer ();
296
+ while (matcher .find ()) {
297
+ String content = matcher .group (1 ).replace ("\\ " , "\\ \\ " ).replace ("." , "\\ ." );
298
+ matcher .appendReplacement (sb , "'" + content + "'" );
299
+ }
300
+ matcher .appendTail (sb );
301
+ return sb .toString ();
302
+ }
303
+
290
304
public SearchRequest build () {
291
305
return this .searchRequest ;
292
306
}
You can’t perform that action at this time.
0 commit comments