Skip to content

Commit b32f982

Browse files
committed
improved search
1 parent d40b2b0 commit b32f982

2 files changed

Lines changed: 138 additions & 8 deletions

File tree

scripts/main.js

Lines changed: 115 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -774,26 +774,60 @@
774774
return a.entry.title.localeCompare(b.entry.title);
775775
});
776776

777-
var topResults = matches.slice(0, 50).map(function(item) {
777+
var topResults = matches.slice(0, 100).map(function(item) {
778778
return item.entry;
779779
});
780780

781781
renderSearchResults(topResults, query);
782782
}
783783

784784
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) {
786790
return 0;
787791
}
788-
if (entry.titleLower.indexOf(normalizedQuery) === 0) {
792+
793+
// Starts with query - very high priority
794+
if (titleLower.indexOf(normalizedQuery) === 0) {
789795
return 1;
790796
}
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) {
792801
return 2;
793802
}
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+
}
796829
}
830+
797831
return Infinity;
798832
}
799833

@@ -1040,7 +1074,7 @@
10401074
});
10411075
}
10421076

1043-
if (headingText.indexOf('property') !== -1) {
1077+
if (headingText.indexOf('property') !== -1 || headingText.indexOf('properties') !== -1) {
10441078
var propertyNames = collectPropertyNames(section);
10451079
var anchorId = section.getAttribute('id');
10461080
var anchorHref = anchorId ? baseHref + '#' + anchorId : baseHref;
@@ -1061,6 +1095,80 @@
10611095
});
10621096
}
10631097
}
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+
});
10641172
});
10651173

10661174
return entries;

styles/main.css

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ body {
173173

174174
#leftPane .search-results {
175175
list-style: none;
176-
max-height: 240px;
176+
max-height: 320px;
177177
overflow-y: auto;
178178
margin: 0;
179179
padding: 0 0 8px 0;
@@ -204,6 +204,28 @@ body {
204204
margin-top: 2px;
205205
}
206206

207+
/* Search result type indicators */
208+
#leftPane .search-result-object .result-meta::before {
209+
content: "○ ";
210+
font-weight: bold;
211+
}
212+
213+
#leftPane .search-result-method .result-meta::before {
214+
content: "ƒ ";
215+
font-weight: bold;
216+
}
217+
218+
#leftPane .search-result-property .result-meta::before {
219+
content: "◆ ";
220+
font-weight: bold;
221+
}
222+
223+
#leftPane .search-result-value .result-meta::before,
224+
#leftPane .search-result-constant .result-meta::before {
225+
content: "◇ ";
226+
font-weight: bold;
227+
}
228+
207229
#leftPane ul.nav-tree {
208230
list-style-type: none;
209231
margin: 0;

0 commit comments

Comments
 (0)