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);
            console.log('Subobject query:', subQuery);
         });
         });
          
          
Line 991: Line 990:
             var isFirst = true;
             var isFirst = true;
              
              
             results.forEach(function(data, queryIndex) {
             results.forEach(function(data) {
                console.log('Subobject query', queryIndex, 'response:', data);
               
                 // Check for SMW errors
                 // Check for SMW errors
                 if (data.error) {
                 if (data.error) {
                    console.error('Subobject query', queryIndex, 'error:', 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) {
                    var resultCount = Object.keys(data.query.results).length;
                    console.log('Subobject query', queryIndex, 'found', resultCount, 'subobjects');
                   
                     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:
                         }
                         }
                     });
                     });
                    console.log('Subobject query', queryIndex, 'matched', currentMatches.size, 'CRT models');
                 }
                 }
                  
                  
Line 1,026: Line 1,018:
                 }
                 }
             });
             });
           
            console.log('Total matching models after intersection:', matchingModels.size);
              
              
             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();
       
        console.log('fetchModelDetailsBatched: Total models:', allModels.length, 'Offset:', currentOffset);
          
          
         // Get just the models for the current page
         // Get just the models for the current page
Line 1,071: Line 1,059:
             return;
             return;
         }
         }
       
        console.log('fetchModelDetailsBatched: Page models:', pageModels.length);
          
          
         // 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));
         }
         }
       
        console.log('fetchModelDetailsBatched: Batches:', batches.length);
          
          
         // Build and execute batched queries
         // Build and execute batched queries
         var batchPromises = batches.map(function(batch, batchIndex) {
         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;
             }
             }
           
            var fullQuery = 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';
           
            console.log('Batch', batchIndex, 'query:', fullQuery.substring(0, 200) + '...');
              
              
             return api.get({
             return api.get({
                 action: 'ask',
                 action: 'ask',
                 query: fullQuery,
                 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, index) {
             batchResults.forEach(function(data) {
                console.log('Batch', index, 'response:', data);
               
                 // Check for SMW errors in the response
                 // Check for SMW errors in the response
                 if (data.error) {
                 if (data.error) {
                    console.error('Batch', index, 'SMW error:', 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) {
                    var resultCount = Object.keys(data.query.results).length;
                    console.log('Batch', index, 'returned', resultCount, 'results');
                     Object.assign(mergedResults, data.query.results);
                     Object.assign(mergedResults, data.query.results);
                } else {
                    console.warn('Batch', index, 'returned no results');
                 }
                 }
             });
             });
Line 1,156: Line 1,129:
                 sortedResults[key] = mergedResults[key];
                 sortedResults[key] = mergedResults[key];
             });
             });
           
            console.log('Total merged results:', Object.keys(sortedResults).length);
              
              
             isLoading = false;
             isLoading = false;
MediaWiki Appliance - Powered by TurnKey Linux