MediaWiki:CRT Search.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 974: | Line 974: | ||
subQuery += '|?Has CRT model|limit=5000|format=json'; | subQuery += '|?Has CRT model|limit=5000|format=json'; | ||
subQueries.push(subQuery); | subQueries.push(subQuery); | ||
}); | }); | ||
| Line 991: | Line 990: | ||
var isFirst = true; | var isFirst = true; | ||
results.forEach(function(data | results.forEach(function(data) { | ||
// Check for SMW errors | // Check for SMW errors | ||
if (data.error) { | if (data.error) { | ||
return; | return; | ||
} | } | ||
| Line 1,002: | Line 998: | ||
var currentMatches = new Set(); | var currentMatches = new Set(); | ||
if (data.query && data.query.results) { | if (data.query && data.query.results) { | ||
Object.values(data.query.results).forEach(function(result) { | Object.values(data.query.results).forEach(function(result) { | ||
if (result.printouts && result.printouts['Has CRT model']) { | if (result.printouts && result.printouts['Has CRT model']) { | ||
| Line 1,013: | Line 1,006: | ||
} | } | ||
}); | }); | ||
} | } | ||
| Line 1,026: | Line 1,018: | ||
} | } | ||
}); | }); | ||
if (matchingModels.size === 0) { | if (matchingModels.size === 0) { | ||
| Line 1,060: | Line 1,050: | ||
function fetchModelDetailsBatched(allModels, mainConditions, sortProperty) { | function fetchModelDetailsBatched(allModels, mainConditions, sortProperty) { | ||
var api = new mw.Api(); | var api = new mw.Api(); | ||
// Get just the models for the current page | // Get just the models for the current page | ||
| Line 1,071: | Line 1,059: | ||
return; | return; | ||
} | } | ||
// Split into small batches to avoid SMW query size limits | // Split into small batches to avoid SMW query size limits | ||
| Line 1,081: | Line 1,067: | ||
batches.push(pageModels.slice(i, i + BATCH_SIZE)); | batches.push(pageModels.slice(i, i + BATCH_SIZE)); | ||
} | } | ||
// Build and execute batched queries | // Build and execute batched queries | ||
var batchPromises = batches.map(function(batch | var batchPromises = batches.map(function(batch) { | ||
// Use disjunction with || instead of separate [[]] OR [[]] to reduce query depth | // Use disjunction with || instead of separate [[]] OR [[]] to reduce query depth | ||
var disjunction = batch.join('||'); | var disjunction = batch.join('||'); | ||
| Line 1,094: | Line 1,078: | ||
query = '[[Category:CRT models]]' + mainConditions + query; | query = '[[Category:CRT models]]' + mainConditions + query; | ||
} | } | ||
return api.get({ | return api.get({ | ||
action: 'ask', | action: 'ask', | ||
query: | query: query + | ||
'|?Has image#100px=image' + | |||
'|?Has brand=brand' + | |||
'|?Has model code=model' + | |||
'|?Has CRT type=type' + | |||
'|?Has screen size inches=size' + | |||
'|?Has aspect ratio=aspect' + | |||
'|?Has TVL=tvl' + | |||
'|limit=50' + | |||
'|format=json', | |||
format: 'json' | format: 'json' | ||
}); | }); | ||
| Line 1,120: | Line 1,100: | ||
var hasErrors = false; | var hasErrors = false; | ||
batchResults.forEach(function(data | batchResults.forEach(function(data) { | ||
// Check for SMW errors in the response | // Check for SMW errors in the response | ||
if (data.error) { | if (data.error) { | ||
hasErrors = true; | hasErrors = true; | ||
return; | return; | ||
| Line 1,131: | Line 1,108: | ||
if (data.query && data.query.results) { | if (data.query && data.query.results) { | ||
Object.assign(mergedResults, data.query.results); | Object.assign(mergedResults, data.query.results); | ||
} | } | ||
}); | }); | ||
| Line 1,156: | Line 1,129: | ||
sortedResults[key] = mergedResults[key]; | sortedResults[key] = mergedResults[key]; | ||
}); | }); | ||
isLoading = false; | isLoading = false; | ||