|
774 | 774 | return a.entry.title.localeCompare(b.entry.title); |
775 | 775 | }); |
776 | 776 |
|
777 | | - var topResults = matches.slice(0, 50).map(function(item) { |
| 777 | + var topResults = matches.slice(0, 100).map(function(item) { |
778 | 778 | return item.entry; |
779 | 779 | }); |
780 | 780 |
|
781 | 781 | renderSearchResults(topResults, query); |
782 | 782 | } |
783 | 783 |
|
784 | 784 | function evaluateMatch(entry, normalizedQuery) { |
785 | | - if (entry.titleLower === normalizedQuery) { |
| 785 | + var titleLower = entry.titleLower; |
| 786 | + var searchBlob = entry.searchBlob || ''; |
| 787 | + |
| 788 | + // Exact match - highest priority |
| 789 | + if (titleLower === normalizedQuery) { |
786 | 790 | return 0; |
787 | 791 | } |
788 | | - if (entry.titleLower.indexOf(normalizedQuery) === 0) { |
| 792 | + |
| 793 | + // Starts with query - very high priority |
| 794 | + if (titleLower.indexOf(normalizedQuery) === 0) { |
789 | 795 | return 1; |
790 | 796 | } |
791 | | - if (entry.titleLower.indexOf(normalizedQuery) !== -1) { |
| 797 | + |
| 798 | + // Query appears in title - high priority |
| 799 | + var titleIndex = titleLower.indexOf(normalizedQuery); |
| 800 | + if (titleIndex !== -1) { |
792 | 801 | return 2; |
793 | 802 | } |
794 | | - if (entry.searchBlob && entry.searchBlob.indexOf(normalizedQuery) !== -1) { |
795 | | - return 3; |
| 803 | + |
| 804 | + // Check for word boundary matches in title (e.g., "CONTENT" matches "CONTENT_AWARE_FITTING") |
| 805 | + var titleParts = titleLower.split(/[._\s-]+/); |
| 806 | + for (var i = 0; i < titleParts.length; i++) { |
| 807 | + if (titleParts[i] === normalizedQuery) { |
| 808 | + return 2.5; // Between substring match and blob match |
| 809 | + } |
| 810 | + if (titleParts[i].indexOf(normalizedQuery) === 0) { |
| 811 | + return 3; |
| 812 | + } |
| 813 | + } |
| 814 | + |
| 815 | + // Match in search blob (context, description, keywords) - lower priority |
| 816 | + if (searchBlob && searchBlob.indexOf(normalizedQuery) !== -1) { |
| 817 | + return 4; |
| 818 | + } |
| 819 | + |
| 820 | + // Try fuzzy matching for partial words in search blob |
| 821 | + var queryWords = normalizedQuery.split(/\s+/); |
| 822 | + if (queryWords.length > 1 && searchBlob) { |
| 823 | + var allWordsMatch = queryWords.every(function(word) { |
| 824 | + return searchBlob.indexOf(word) !== -1; |
| 825 | + }); |
| 826 | + if (allWordsMatch) { |
| 827 | + return 5; |
| 828 | + } |
796 | 829 | } |
| 830 | + |
797 | 831 | return Infinity; |
798 | 832 | } |
799 | 833 |
|
|
1040 | 1074 | }); |
1041 | 1075 | } |
1042 | 1076 |
|
1043 | | - if (headingText.indexOf('property') !== -1) { |
| 1077 | + if (headingText.indexOf('property') !== -1 || headingText.indexOf('properties') !== -1) { |
1044 | 1078 | var propertyNames = collectPropertyNames(section); |
1045 | 1079 | var anchorId = section.getAttribute('id'); |
1046 | 1080 | var anchorHref = anchorId ? baseHref + '#' + anchorId : baseHref; |
|
1061 | 1095 | }); |
1062 | 1096 | } |
1063 | 1097 | } |
| 1098 | + |
| 1099 | + // Index values/constants/enums (like CONTENT_AWARE_FITTING) |
| 1100 | + if (headingText.indexOf('value') !== -1 || headingText.indexOf('constant') !== -1) { |
| 1101 | + var valueRows = section.querySelectorAll('table tbody tr'); |
| 1102 | + valueRows.forEach(function(row) { |
| 1103 | + var cells = row.querySelectorAll('td'); |
| 1104 | + if (!cells.length) { |
| 1105 | + return; |
| 1106 | + } |
| 1107 | + var nameCell = cells[0]; |
| 1108 | + var descCell = cells.length > 1 ? cells[1] : null; |
| 1109 | + |
| 1110 | + // Extract the value name (e.g., "Fitting.CONTENT_AWARE_FITTING") |
| 1111 | + var clipButton = nameCell.querySelector('.clip_button'); |
| 1112 | + var text = clipButton ? clipButton.textContent.trim() : nameCell.textContent.trim(); |
| 1113 | + |
| 1114 | + if (!text) { |
| 1115 | + return; |
| 1116 | + } |
| 1117 | + |
| 1118 | + // Get description for better search context |
| 1119 | + var description = descCell ? descCell.textContent.trim() : ''; |
| 1120 | + var keywords = description ? description.toLowerCase() : ''; |
| 1121 | + |
| 1122 | + // Use section anchor or base href |
| 1123 | + var anchorId = section.getAttribute('id'); |
| 1124 | + var resolved = anchorId ? baseHref + '#' + anchorId : baseHref; |
| 1125 | + |
| 1126 | + pushEntry(buildSearchEntry('value', text, resolved, { |
| 1127 | + context: pageTitle, |
| 1128 | + keywords: keywords |
| 1129 | + })); |
| 1130 | + }); |
| 1131 | + } |
| 1132 | + }); |
| 1133 | + |
| 1134 | + // Also index all tables that might contain constants/values outside of sections |
| 1135 | + var allTables = doc.querySelectorAll('table'); |
| 1136 | + allTables.forEach(function(table) { |
| 1137 | + // Check if table has class indicators or if it's in body |
| 1138 | + var inSection = table.closest('div.section'); |
| 1139 | + if (inSection) { |
| 1140 | + return; // Already processed in sections |
| 1141 | + } |
| 1142 | + |
| 1143 | + var rows = table.querySelectorAll('tbody tr'); |
| 1144 | + rows.forEach(function(row) { |
| 1145 | + var cells = row.querySelectorAll('td'); |
| 1146 | + if (cells.length < 1) { |
| 1147 | + return; |
| 1148 | + } |
| 1149 | + var nameCell = cells[0]; |
| 1150 | + var descCell = cells.length > 1 ? cells[1] : null; |
| 1151 | + |
| 1152 | + // Look for clip_button or structured content |
| 1153 | + var clipButton = nameCell.querySelector('.clip_button'); |
| 1154 | + if (!clipButton) { |
| 1155 | + return; |
| 1156 | + } |
| 1157 | + |
| 1158 | + var text = clipButton.textContent.trim(); |
| 1159 | + if (!text) { |
| 1160 | + return; |
| 1161 | + } |
| 1162 | + |
| 1163 | + // Get description for context |
| 1164 | + var description = descCell ? descCell.textContent.trim() : ''; |
| 1165 | + var keywords = description ? description.toLowerCase() : ''; |
| 1166 | + |
| 1167 | + pushEntry(buildSearchEntry('constant', text, baseHref, { |
| 1168 | + context: pageTitle, |
| 1169 | + keywords: keywords |
| 1170 | + })); |
| 1171 | + }); |
1064 | 1172 | }); |
1065 | 1173 |
|
1066 | 1174 | return entries; |
|
0 commit comments