Commit ec4612b
committed
feat: add multiple prefix support to SearchIndex.fromExisting()
Port of Python RedisVL multiple prefix support (PR #392, commit c3c1733).
Enables SearchIndex.fromExisting() to preserve all prefixes from Redis
indices that were created with multiple PREFIX values, not just the first.
Implementation handles Union[String, List<String>] prefix type to match
Python behavior. Normalizes to first prefix for Redis key construction
while preserving all prefixes in schema definition for comparison and
serialization.
Changes:
**IndexSchema.Index:**
- Changed `prefix` field from String to Object (supports String or List<String>)
- Added `getPrefix()` - normalizes to first prefix for key construction
- Added `getPrefixRaw()` - returns raw prefix (String or List)
- Added `setPrefix(List<String>)` - overload with single-element normalization
- Added package-private `setPrefixRaw(Object)` for builder use
- Updated `getIndex()` to preserve raw prefix in defensive copy
**IndexSchema.Builder:**
- Updated `prefix` field to Object type
- Added `prefix(List<String>)` overload with normalization
- Updated `build()` to set raw prefix for multi-element lists
- Updated `index(Index)` to use getPrefixRaw()
**SearchIndex:**
- Updated `fromExisting()` to preserve all prefixes
- Normalizes single-element prefix lists to strings for backward compatibility
- Captures all prefixes when multiple are configured
**Tests:**
- New IndexSchemaPrefixTest with 6 unit tests
- New integration test testFromExistingMultiplePrefixes()
- All tests verify backward compatibility and multi-prefix handling
Test Coverage:
- Single prefix as String (backward compatible)
- Single-element prefix list normalized to String
- Multiple prefixes preserved as List
- getPrefix() returns first prefix for key construction
- getPrefixRaw() returns original List or String
- Serialization preserves multiple prefixes
- Integration test with real Redis index
Backward compatibility maintained by normalizing single-element prefix
lists to strings when loading from Redis. Ensures schema comparisons
work correctly between existing and new index configurations.
Python reference: /redis-vl-python/tests/unit/test_convert_index_info.py
Python reference: /redis-vl-python/tests/integration/test_search_index.py:172-243
Resolves #258, #3921 parent 6896339 commit ec4612b
File tree
4 files changed
+305
-12
lines changed- core/src
- main/java/com/redis/vl
- index
- schema
- test/java/com/redis/vl
- index
- schema
4 files changed
+305
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
379 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
380 | 386 | | |
381 | 387 | | |
382 | 388 | | |
| |||
Lines changed: 106 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
475 | | - | |
476 | | - | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
477 | 478 | | |
478 | 479 | | |
479 | 480 | | |
| |||
498 | 499 | | |
499 | 500 | | |
500 | 501 | | |
501 | | - | |
| 502 | + | |
| 503 | + | |
502 | 504 | | |
503 | 505 | | |
504 | 506 | | |
| |||
564 | 566 | | |
565 | 567 | | |
566 | 568 | | |
567 | | - | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
568 | 576 | | |
569 | 577 | | |
570 | 578 | | |
| |||
599 | 607 | | |
600 | 608 | | |
601 | 609 | | |
602 | | - | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
603 | 614 | | |
604 | | - | |
| 615 | + | |
605 | 616 | | |
606 | 617 | | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
607 | 635 | | |
608 | 636 | | |
609 | 637 | | |
610 | 638 | | |
611 | | - | |
| 639 | + | |
612 | 640 | | |
613 | 641 | | |
614 | 642 | | |
615 | 643 | | |
616 | 644 | | |
617 | 645 | | |
618 | 646 | | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
619 | 675 | | |
620 | 676 | | |
621 | 677 | | |
| |||
673 | 729 | | |
674 | 730 | | |
675 | 731 | | |
676 | | - | |
| 732 | + | |
677 | 733 | | |
678 | 734 | | |
679 | 735 | | |
| |||
691 | 747 | | |
692 | 748 | | |
693 | 749 | | |
694 | | - | |
| 750 | + | |
695 | 751 | | |
696 | 752 | | |
697 | 753 | | |
| |||
701 | 757 | | |
702 | 758 | | |
703 | 759 | | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
704 | 781 | | |
705 | 782 | | |
706 | 783 | | |
| |||
811 | 888 | | |
812 | 889 | | |
813 | 890 | | |
814 | | - | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
815 | 910 | | |
816 | 911 | | |
817 | 912 | | |
| |||
822 | 917 | | |
823 | 918 | | |
824 | 919 | | |
825 | | - | |
| 920 | + | |
826 | 921 | | |
827 | 922 | | |
828 | 923 | | |
| |||
Lines changed: 82 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1016 | 1016 | | |
1017 | 1017 | | |
1018 | 1018 | | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
1019 | 1101 | | |
0 commit comments