Expand a user query with retrieval-friendly terms while keeping the original intent.
Full problem description visible. Upgrade to unlock the editor, test cases, and solution.
Implement rewrite_query(query, expander) that produces an expanded search query.
- query is the original user query string.
- expander(query) -> list[str] returns expansion terms relevant to the query.
- Preserve the original query verbatim in the output.
- Append expansion terms separated by spaces, each prefixed with a + sign.
- If expander returns an empty list, return the original query unchanged.
- Avoid duplicating words that already appear in the original query (case-insensitive check).
₹999/monthLimited period launch pricing.
Get the full problem statement, test cases, interactive editor, solution explanation, and visual diagram.
def rewrite_query(query, expander):
"""Expand a search query with retrieval-friendly terms while preserving the original."""Expansion filtering loop
Already have Pro access? Sign in