Conversation
Greptile SummaryReplaces Key Changes:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| backend/donations/views/common/search.py | Adds probable_registration_number() helper and new ImprovedCauseSearchMixin with exact match fallback and registration number search |
| backend/donations/views/api.py | Updates SearchCausesApi to use ImprovedCauseSearchMixin instead of NgoCauseMixedSearchMixin |
| backend/donations/views/site.py | Updates NgoListHandler to use ImprovedCauseSearchMixin instead of NgoCauseMixedSearchMixin |
| backend/redirectioneaza/settings/feature_flags.py | Adds ENABLE_CAUSE_SEARCH_EXACT_MATCH feature flag defaulting to True |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User Search Query] --> B[ImprovedCauseSearchMixin.get_search_results]
B --> C{ENABLE_CAUSE_SEARCH_EXACT_MATCH?}
C -->|Yes| D[Build Exact Match Filter]
D --> E[name__icontains query]
D --> F{Query looks like registration number?}
F -->|Yes| G[probable_registration_number helper]
G --> H{Starts with RO + numeric?}
G --> I{Only numeric?}
H -->|Yes| J[Extract numeric part]
I -->|Yes| K[Use as-is]
J --> L[Add filter: ngo__registration_number + is_main=True]
K --> L
F -->|No| M[Execute exact_causes query]
L --> M
E --> M
M --> N{Has exact matches?}
N -->|Yes| O[Return exact matches]
N -->|No| P[Fall through to fuzzy search]
C -->|No| P
P --> Q[Build SearchVector + SearchQuery]
Q --> R{ENABLE_CAUSE_SEARCH_WORD_SIMILARITY?}
R -->|Yes| S[Use TrigramWordSimilarity threshold 0.4]
R -->|No| T[Use TrigramSimilarity threshold 0.3]
S --> U[Execute fuzzy_causes query]
T --> U
U --> V[Return fuzzy results]
O --> W[Return to API/View]
V --> W
Last reviewed commit: 4b5a501
tudoramariei
left a comment
There was a problem hiding this comment.
The most important thing is this comment
https://github.com/code4romania/redirectioneaza/pull/658/changes#r2832804852
and then check if the other things still make sense
| # If the query looks like a registration number then also try to find the main causes owned by | ||
| # organisations which have that registration number | ||
| if registration_number: | ||
| query_filter = query_filter | (Q(ngo__registration_number=registration_number) & Q(is_main=True)) |
There was a problem hiding this comment.
Shouldn't we remove the initial query_filter?
If we have a registration number, it feels redundant to search in the name for it.
There was a problem hiding this comment.
We don't know if we have a real registration number or just some plain text.
| if exact_causes.count(): | ||
| return exact_causes | ||
|
|
||
| search_vector: SearchVector = ConfigureSearch.vector(("name",), language_code) |
There was a problem hiding this comment.
Should the vector be configured by what we're searching?
I think it should be changed to the registration number if we're going on that path.
| registration_number = probable_registration_number(query) | ||
| # If the query looks like a registration number then also try to find the main causes owned by | ||
| # organisations which have that registration number | ||
| if registration_number: |
There was a problem hiding this comment.
Search is a bit annoying, but we should take into account one path if we get a registration number (CIF) and a different one if it isn't that.
It seems a bit more straightforward if it's a registration number and we may need to just run a filter with Q(ngo__registration_number=registration_number) & Q(is_main=True) and not much more (we probably don't need search vectors or other things.
In this if statement I'd branch out things and directly return Cause.objects.filter(Q(ngo__registration_number=registration_number) & Q(is_main=True)) or something like that
Simplifies the flow and leaves a clearer trail to follow once you only have the name.
No description provided.