Repository navigation
Find hadiths stored under a combined number (#614) - #3993
Open
wakqasahmed wants to merge 1 commit into
Open
wakqasahmed wants to merge 1 commit into
wakqasahmed wants to merge 1 commit into
Conversation
Some hadiths are stored with a combined hadithNumber such as "6924, 6925", so looking up 6924 or 6925 on its own returned 404. When the exact match finds nothing, fall back to a LIKE search and keep rows where the number is one of the comma or dash separated parts, as sunnah.com does in Util::getURNByNumber.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some hadiths are stored under a combined number like
"6924, 6925", so/v1/collections/bukhari/hadiths/6924and.../6925both returned 404 because every lookup was an exact match onhadithNumber.I followed what the website already does in
Util::getURNByNumber: try the exact match first, and only if that finds nothing, do aLIKE '%<n>%'search and keep the rows where the number equals one of the trimmed parts after splitting on,or-. The split/match bit lives in a smallhadith_number.pyso it can be unit tested without a database (main.pycan't be imported in tests becausemodels.pyreflects against MySQL). The LIKE uses a bound param withautoescape, so%or_in the URL don't act as wildcards. I used the same fallback forGET /v1/hadiths?hadithNumber=since it's the same one-line swap. I left/v1/hadiths/refsalone because it batches all refs into a single OR query and would need a separate second pass, and I didn't touch the Muslim letter-suffix handling (#1456).To check it, I ran the repo's docker compose stack and added one copy of Bukhari 1 to the sample DB with
hadithNumber = '6924, 6925'.Before:
After:
I also added
tests/test_hadith_number.py.python3 -m unittest tests.test_hadith_number tests.test_text_transformpasses (10 tests), and black/flake8 are clean on the lines I changed.Fixes #614