Skip to content

Conversation

@danniel
Copy link
Collaborator

@danniel danniel commented Feb 11, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Adjusted cause search result ordering to prioritize more relevant results in mixed searches.
  • Improvements

    • Refined search algorithm selection for cause searches to improve matching accuracy.

@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new feature flag ENABLE_CAUSE_SEARCH_WORD_SIMILARITY for fine-grained control over cause search behavior and reorders the search result union to prioritize cause search results over NGO matches in mixed search scenarios.

Changes

Cohort / File(s) Summary
Feature Flag Addition
backend/redirectioneaza/settings/feature_flags.py
Added new feature flag ENABLE_CAUSE_SEARCH_WORD_SIMILARITY (defaults to False) in the search tweaks section.
Search Logic Updates
backend/donations/views/common/search.py
Updated CauseSearchMixin to check ENABLE_CAUSE_SEARCH_WORD_SIMILARITY instead of ENABLE_NGO_SEARCH_WORD_SIMILARITY for trigram similarity behavior. Reversed union precedence in NgoCauseMixedSearchMixin from ngos_causes | searched_causes to searched_causes | ngos_causes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Poem

🐰 A search that learns to find its way,
With flags to guide through night and day,
Causes now leap to the front with grace,
While whiskers twitch at a quicker pace! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic, using the broad term 'Improve' without specifying what aspect of the search backend was improved. Make the title more specific by identifying the key improvement, such as 'Add feature flag for cause search word similarity' or 'Adjust search result precedence for mixed cause-NGO queries'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/improve-search-quality-2

No actionable comments were generated in the recent review. 🎉


Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link

greptile-apps bot commented Feb 11, 2026

Greptile Overview

Greptile Summary

Changes introduce a new feature flag to control whether Cause search uses trigram word similarity (vs regular trigram similarity), aligning Cause search with existing NGO search tuning. In the mixed NGO+Cause search, the queryset union order was swapped so that results from the direct Cause search appear before causes inferred from matching NGOs.

These changes live in the shared search mixins used by list views, and the new flag is loaded into Django settings via the existing settings/__init__.py wildcard import.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • The diff is small and the new feature flag is correctly wired into settings; the behavior change is limited to search ranking/ordering and uses existing Postgres search primitives already used elsewhere in this codebase.
  • backend/donations/views/common/search.py (confirm union ordering change is intended)

Important Files Changed

Filename Overview
backend/donations/views/common/search.py Switched Cause search similarity flag and changed union order in mixed search; needs verification that queryset union ordering change is intended and deterministic.
backend/redirectioneaza/settings/feature_flags.py Added ENABLE_CAUSE_SEARCH_WORD_SIMILARITY flag; appears correctly imported via settings/init.py.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant V as Search View (CommonSearchMixin)
    participant CS as CauseSearchMixin
    participant NS as NgoSearchMixin
    participant DB as Postgres (FTS + trigram)

    U->>V: GET /... ?q=query
    V->>V: _search_query() + min length checks
    V->>CS: get_search_results(queryset, query, language)
    CS->>CS: build SearchVector/SearchQuery
    alt ENABLE_CAUSE_SEARCH_WORD_SIMILARITY
        CS->>CS: TrigramWordSimilarity(query, "name")
    else
        CS->>CS: TrigramSimilarity("name", query)
    end
    CS->>DB: annotate(rank, similarity) + filter + distinct
    DB-->>CS: causes queryset
    CS-->>V: results

    note over V,NS: Mixed search path
    V->>NS: NgoSearchMixin.get_search_results(Ngo.active,...)
    NS->>DB: search NGOs
    DB-->>NS: ngos queryset
    V->>DB: Cause.public_active.filter(ngo__in=ngos)
    DB-->>V: ngos_causes queryset
    V->>CS: CauseSearchMixin.get_search_results(queryset,...)
    CS-->>V: searched_causes queryset
    V-->>U: searched_causes | ngos_causes
Loading

@danniel danniel merged commit 3df84b1 into main Feb 11, 2026
10 checks passed
@danniel danniel deleted the feature/improve-search-quality-2 branch February 11, 2026 13:01
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.

1 participant