Skip to content

Commit fb03f59

Browse files
committed
תיקון issue #4497 — סינון ניווט PDF: דף עם סימן עמוד כמילה שלמה, ודירוג מדויק/תחילית
הנרמול של האיתור (3602983, 15.6) מוחק "." ו-":", ולכן בחלונית הניווט של PDF "ב." תאם כל כותרת שיש בה ב (יב., נב., קב. …) ו"קיא:" היה שווה ל"קיא.". הסינון שמר את סדר תוכן העניינים בלי דירוג (נשמר גם ב-7592b6240), כך שהשורות הראשונות היו דפים אחרים. שאילתה שמסתיימת בסימן עמוד מחפשת עכשיו את הדף כמילה שלמה בכותרת, עם אותו סימן עמוד או בלי סימן; והתוצאות מדורגות מדויק, תחילית ואז הכלה (findNormalizedTextMatchRank), ובתוך דרגה לפי סדר תוכן העניינים. normalizeFindText לא השתנה.
1 parent 630471f commit fb03f59

2 files changed

Lines changed: 50 additions & 10 deletions

File tree

‎lib/pdf_book/view/pdf_outlines_screen.dart‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,51 @@ List<PdfOutlineSearchEntry> filterPdfOutline(
4444
) {
4545
final normalizedQuery = normalizeFindText(rawQuery);
4646
if (normalizedQuery.isEmpty) return entries;
47-
return entries
48-
.where(
49-
(e) => findNormalizedTextMatches(
50-
normalizedQuery: normalizedQuery,
51-
normalizedPrimaryText: e.normalizedTitle,
52-
),
53-
)
54-
.toList();
47+
// הנרמול מוחק "." ו-":", ולכן "ב." היה תואם כל כותרת עם האות ב ו"קיא:"
48+
// היה שווה ל"קיא.". שאילתה שמסתיימת בסימן עמוד מחפשת את הדף כמילה שלמה.
49+
final amud = _amudMark(rawQuery);
50+
final daf = amud == null
51+
? null
52+
: normalizedQuery.substring(normalizedQuery.lastIndexOf(' ') + 1);
53+
final matches = <({int rank, int index})>[];
54+
for (var i = 0; i < entries.length; i++) {
55+
final title = entries[i].normalizedTitle;
56+
if (!title.contains(normalizedQuery)) continue;
57+
if (daf != null && !_titleHasDaf(entries[i].node.title, daf, amud!)) {
58+
continue;
59+
}
60+
final rank = findNormalizedTextMatchRank(
61+
normalizedQuery: normalizedQuery,
62+
normalizedPrimaryText: title,
63+
);
64+
matches.add((rank: rank, index: i));
65+
}
66+
// מדויק, תחילית ואז הכלה; בתוך כל דרגה — סדר תוכן העניינים.
67+
matches.sort(
68+
(a, b) => a.rank != b.rank ? a.rank - b.rank : a.index - b.index,
69+
);
70+
return [for (final m in matches) entries[m.index]];
5571
}
5672

73+
String? _amudMark(String text) {
74+
final trimmed = text.trimRight();
75+
if (trimmed.endsWith('.')) return '.';
76+
if (trimmed.endsWith(':')) return ':';
77+
return null;
78+
}
79+
80+
/// האם יש בכותרת מילה שהיא הדף [daf], בלי סימן עמוד או עם הסימן [amud].
81+
bool _titleHasDaf(String rawTitle, String daf, String amud) {
82+
for (final word in rawTitle.split(_whitespace)) {
83+
if (normalizeFindText(word) != daf) continue;
84+
final mark = _amudMark(word);
85+
if (mark == null || mark == amud) return true;
86+
}
87+
return false;
88+
}
89+
90+
final RegExp _whitespace = RegExp(r'\s+');
91+
5792
class OutlineView extends StatefulWidget {
5893
const OutlineView({
5994
super.key,

‎test/pdf_book/pdf_outline_search_filter_test.dart‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ void main() {
1616
_node('מסכת חולין', [_node('דף קו')]),
1717
];
1818

19-
test('הסינון זהה לבדיקת כותרת בודדת, באותו סדר ועם אותן רמות', () {
19+
test('הסינון זהה לבדיקת כותרת בודדת, עם אותן רמות', () {
2020
final entries = flattenPdfOutlineForSearch(outline);
2121
for (final query in [
2222
'',
2323
'בבא',
24-
'דף',
2524
'מסכת',
2625
'הקדמה',
2726
'חולין קו',
@@ -33,6 +32,12 @@ void main() {
3332
.toList();
3433
expect(filterPdfOutline(entries, query), expected, reason: query);
3534
}
35+
// תחילית קודמת להכלה (issue #4497); בתוך דרגה — סדר תוכן העניינים.
36+
expect(filterPdfOutline(entries, 'דף').map((e) => e.node.title), [
37+
'דף ג',
38+
'דף קו',
39+
'בָּבָא בַּתְרָא דף ב',
40+
]);
3641
expect(entries.map((e) => (e.node.title, e.level)).toList(), [
3742
('הַקְדָּמָה', 0),
3843
('מסכת ב"ב', 0),

0 commit comments

Comments
 (0)