Skip to content

Conversation

@bsbodden
Copy link
Collaborator

Implements text field weights functionality allowing users to prioritize certain fields over others in full-text search queries.

Python Reference: PR #384 (redis/redis-vl-python#384)
Test Reference: tests/unit/test_text_query_weights.py (123 lines)

Implementation:

  • TextQuery now accepts Map<String, Double> for textFieldWeights
  • Builder pattern with textField() for single field (backward compatible)
  • Builder method textFieldWeights() for multiple fields with custom weights
  • Query syntax: @field:(terms) => { $weight: 5.0 } for non-default weights
  • Multiple fields joined with OR operator in parentheses
  • Dynamic weight updates via setFieldWeights() method

Validation:

  • Rejects negative weights (IllegalArgumentException)
  • Rejects zero weights (IllegalArgumentException)
  • Ensures all weights are positive numbers
  • Maintains backward compatibility with single string field API

Breaking Changes:

  • TextQuery constructor changed to private (use Builder instead)
  • Updated QueryIntegrationTest to use builder pattern

Tests: 7 unit tests added (TextQueryWeightsTest)

  • testTextQueryAcceptsWeightsDict
  • testTextQueryGeneratesWeightedQueryString
  • testTextQueryMultipleFieldsWithWeights
  • testTextQueryBackwardCompatibility
  • testTextQueryRejectsNegativeWeights
  • testTextQueryRejectsZeroWeights
  • testSetFieldWeightsMethod

All tests pass: 289 tests, 14 skipped

Files Modified:

  • core/src/main/java/com/redis/vl/query/TextQuery.java (complete rewrite)
  • core/src/test/java/com/redis/vl/query/QueryIntegrationTest.java (builder migration)

Files Created:

  • core/src/test/java/com/redis/vl/query/TextQueryWeightsTest.java

Implements text field weights functionality allowing users to prioritize
certain fields over others in full-text search queries.

Python Reference: PR #384 (redis/redis-vl-python#384)
Test Reference: tests/unit/test_text_query_weights.py (123 lines)

Implementation:
- TextQuery now accepts Map<String, Double> for textFieldWeights
- Builder pattern with textField() for single field (backward compatible)
- Builder method textFieldWeights() for multiple fields with custom weights
- Query syntax: @field:(terms) => { $weight: 5.0 } for non-default weights
- Multiple fields joined with OR operator in parentheses
- Dynamic weight updates via setFieldWeights() method

Validation:
- Rejects negative weights (IllegalArgumentException)
- Rejects zero weights (IllegalArgumentException)
- Ensures all weights are positive numbers
- Maintains backward compatibility with single string field API

Breaking Changes:
- TextQuery constructor changed to private (use Builder instead)
- Updated QueryIntegrationTest to use builder pattern

Tests: 7 unit tests added (TextQueryWeightsTest)
- testTextQueryAcceptsWeightsDict
- testTextQueryGeneratesWeightedQueryString
- testTextQueryMultipleFieldsWithWeights
- testTextQueryBackwardCompatibility
- testTextQueryRejectsNegativeWeights
- testTextQueryRejectsZeroWeights
- testSetFieldWeightsMethod

All tests pass: 289 tests, 14 skipped

Files Modified:
- core/src/main/java/com/redis/vl/query/TextQuery.java (complete rewrite)
- core/src/test/java/com/redis/vl/query/QueryIntegrationTest.java (builder migration)

Files Created:
- core/src/test/java/com/redis/vl/query/TextQueryWeightsTest.java
@bsbodden bsbodden merged commit bb86ded into main Oct 22, 2025
4 checks passed
@bsbodden bsbodden deleted the bsb/text_field_weights branch October 22, 2025 22:15
@bsbodden bsbodden self-assigned this Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants