Skip to content

[OSDEV-2033] Fix long string parsing for v1/production-locations query param#646

Merged
VadimKovalenkoSNF merged 25 commits intomainfrom
OSDEV-2033-fix-long-strings-query-param
Jun 16, 2025
Merged

[OSDEV-2033] Fix long string parsing for v1/production-locations query param#646
VadimKovalenkoSNF merged 25 commits intomainfrom
OSDEV-2033-fix-long-strings-query-param

Conversation

@VadimKovalenkoSNF
Copy link
Contributor

@VadimKovalenkoSNF VadimKovalenkoSNF commented Jun 5, 2025

Fix OSDEV-2033

Added support for the slop parameter in multi_match queries when using strings longer than 50 symbols or 12 tokens in GET v1/production-locations?query= endpoint.

@VadimKovalenkoSNF VadimKovalenkoSNF self-assigned this Jun 5, 2025
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@VadimKovalenkoSNF VadimKovalenkoSNF temporarily deployed to Quality Environment June 5, 2025 13:48 — with GitHub Actions Inactive
@coderabbitai
Copy link

coderabbitai bot commented Jun 10, 2025

📝 Walkthrough

"""

Walkthrough

The changes introduce conditional handling of the slop parameter in multi-match queries for production location searches. The query builder and director are updated to use slop for long queries, and corresponding tests are added. Release notes are updated with details on this bugfix and other documentation improvements.

Changes

File(s) Change Summary
doc/release/RELEASE-NOTES.md Expanded release notes with placeholders, added bugfix entry for slop support, and made formatting adjustments.
src/django/api/views/v1/opensearch_query_builder/production_locations_query_builder.py Updated add_multi_match method to accept optional slop parameter and adjust query construction accordingly.
src/django/api/views/v1/opensearch_query_builder/opensearch_query_director.py Modified logic to pass slop=3 to add_multi_match for long queries based on token or character count.
src/django/api/tests/test_production_locations_query_builder.py Added test case to verify add_multi_match behavior when slop is provided.
src/tests/opensearch/test_opensearch.py Updated and added tests for phrase multi_match with slop and exact address match assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_View
    participant QueryDirector
    participant QueryBuilder
    participant OpenSearch

    Client->>API_View: GET /v1/production-locations?query=...
    API_View->>QueryDirector: process_multi_match(query)
    QueryDirector->>QueryBuilder: add_multi_match(query, slop=3) (if long query)
    QueryDirector->>QueryBuilder: add_multi_match(query) (if short query)
    QueryBuilder->>OpenSearch: Constructed query with/without slop
    OpenSearch-->>API_View: Search results
    API_View-->>Client: Response
Loading

Possibly related PRs

Suggested reviewers

  • mazursasha1990
  • Innavin369
    """

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f344d2b and a60a485.

📒 Files selected for processing (1)
  • doc/release/RELEASE-NOTES.md (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
doc/release/RELEASE-NOTES.md (1)

undefined

<retrieved_learning>
Learnt from: VadimKovalenkoSNF
PR: #641
File: doc/release/RELEASE-NOTES.md:6-35
Timestamp: 2025-06-02T13:24:57.659Z
Learning: The Open Supply Hub team keeps placeholders in release notes until code freeze, then fills in the actual content once all changes are finalized for the release.
</retrieved_learning>

🪛 markdownlint-cli2 (0.17.2)
doc/release/RELEASE-NOTES.md

15-15: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


93-93: Multiple headings with the same content
null

(MD024, no-duplicate-heading)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-flake8-linter
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: run-dd-code-quality
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-fe-code-quality
  • GitHub Check: get-base-branch-fe-cov
🔇 Additional comments (2)
doc/release/RELEASE-NOTES.md (2)

10-10: Release date updated
Release date set to June 28, 2025. Ensure this aligns with the scheduled release timeline.


27-29: Bugfix entry looks correct
The OSDEV-2033 entry accurately describes the addition of the slop parameter for long queries.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🧹 Nitpick comments (4)
doc/release/RELEASE-NOTES.md (4)

15-15: Remove trailing colon in section heading.

The #### Migrations: heading has an unnecessary trailing colon; remove it to align with Markdown style guidelines (e.g., #### Migrations).

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

15-15: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


18-18: Unify section heading punctuation.

Unlike Migrations:, the #### Schema changes heading omits a colon. Standardize on either including or omitting terminal punctuation across all headings.


24-24: Duplicate section heading detected.

The ### Architecture/Environment changes heading appears twice (lines 24 and 33). Remove the redundant instance to prevent confusion.

Also applies to: 33-33


28-29: Expand Bugfix entry for clarity.

The OSDEV-2033 entry notes support for slop but could benefit from specifying the slop value used (e.g., slop=3) and referencing tests or behavioral outcomes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d21e13e and 482b976.

📒 Files selected for processing (5)
  • doc/release/RELEASE-NOTES.md (2 hunks)
  • src/django/api/tests/test_production_locations_query_builder.py (1 hunks)
  • src/django/api/views/v1/opensearch_query_builder/opensearch_query_director.py (1 hunks)
  • src/django/api/views/v1/opensearch_query_builder/production_locations_query_builder.py (1 hunks)
  • src/tests/opensearch/test_opensearch.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/django/api/tests/test_production_locations_query_builder.py (2)
src/django/api/views/v1/opensearch_query_builder/opensearch_query_builder.py (1)
  • reset (7-8)
src/django/api/views/v1/opensearch_query_builder/production_locations_query_builder.py (1)
  • add_multi_match (106-132)
src/django/api/views/v1/opensearch_query_builder/production_locations_query_builder.py (1)
src/django/api/views/v1/parameters_list.py (1)
  • V1_PARAMETERS_LIST (1-37)
🪛 markdownlint-cli2 (0.17.2)
doc/release/RELEASE-NOTES.md

15-15: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


44-44: Multiple headings with the same content
null

(MD024, no-duplicate-heading)

🔇 Additional comments (8)
src/django/api/tests/test_production_locations_query_builder.py (1)

251-273: LGTM! Comprehensive test coverage for slop functionality.

The test correctly verifies:

  • Multi-match query structure with slop parameter
  • Phrase type when slop is used
  • Absence of fuzziness in slop-based queries
  • Uses a realistic long query string (52 characters) that triggers the conditional logic

Minor suggestion for improved test clarity:

+        # Test with slop parameter for long queries
         self.builder.reset()

This comment would help clarify the purpose of the second test case within the method.

doc/release/RELEASE-NOTES.md (2)

10-10: Use full month name for release date.

The release date is now spelled out (June) which improves clarity and consistency.


46-46: Use full month name for previous release date.

Spelling out the month (June) for Release 2.6.0 aligns with the formatting choice in Release 2.7.0.

src/tests/opensearch/test_opensearch.py (2)

105-108: Good enhancement to test specificity.

The updated assertion improves test quality by verifying the exact content of the search result rather than just confirming that results exist. This provides better validation of the search functionality.


110-155: Comprehensive integration test for long query functionality.

This test effectively validates the new slop parameter functionality for multi_match queries. The test structure is well-designed:

  • Uses a realistic long query that would trigger the slop behavior
  • Tests multiple fields (name, address, description, local_name) with appropriate boosting
  • Includes filtering by country to match expected production use cases
  • Asserts exact address match to verify correct document retrieval

The test data and query structure align well with the PR objective of handling long strings (>50 characters/12 tokens).

src/django/api/views/v1/opensearch_query_builder/production_locations_query_builder.py (3)

106-112: Well-structured field configuration.

The field definitions are appropriately organized at the beginning of the method with proper boosting weights. The name field receiving a higher boost (^2) makes sense for production location searches.


114-131: Correct implementation of conditional slop handling.

The conditional logic properly handles both use cases:

  • With slop: Uses type: 'phrase' which is the correct query type for phrase matching with slop tolerance
  • Without slop: Maintains backward compatibility using the existing fuzziness approach

This implementation aligns well with OpenSearch best practices where phrase queries with slop are more appropriate for longer, more specific queries, while fuzzy matching works better for shorter queries with potential typos.


132-132:

Details

✅ Verification successful

Verify integration with query director logic.

The implementation correctly appends the query to the bool must clause. Ensure that the calling code (opensearch_query_director.py) properly determines when to pass the slop parameter based on the 50-character/12-token thresholds mentioned in the PR objectives.


🏁 Script executed:

#!/bin/bash
# Description: Verify the query director integration and slop parameter usage
# Expected: Find logic that determines when to pass slop parameter based on query length/token count

echo "Searching for slop parameter usage in query director..."
rg -A 10 -B 5 "slop.*=.*[0-9]" src/django/api/views/v1/opensearch_query_builder/

echo -e "\nSearching for query length/token threshold logic..."
rg -A 10 -B 5 "(50|12).*character|token" src/django/api/views/v1/opensearch_query_builder/

echo -e "\nSearching for add_multi_match calls with slop parameter..."
rg -A 5 -B 5 "add_multi_match.*slop" src/django/api/views/v1/opensearch_query_builder/

Length of output: 11188


Integration with query director logic verified

All multi‐match calls correctly apply the 12‐token/50‐character threshold and pass slop=3, and the builder’s add_multi_match(self, query, slop=None) signature supports an optional slop parameter:

  • In opensearch_query_director.py, __process_multi_match uses
    if len(tokens) > 12 or len(multi_match_query) > 50: self.__builder.add_multi_match(..., slop=3)
    otherwise omits slop.
  • In production_locations_query_builder.py, add_multi_match(query, slop=None) accepts and applies the slop value when provided.

No further changes required.

Copy link
Contributor

@mazursasha1990 mazursasha1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, looks good.
Left one comment related to the formatting improvement.

Copy link
Contributor

@mazursasha1990 mazursasha1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@mazursasha1990 mazursasha1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sonarqubecloud
Copy link

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.

3 participants