Project

General

Profile

« Previous | Next » 

Revision 3181

As a continued fix for http://bugzilla.ecoinformatics.org/show_bug.cgi?id=2469,
I've fixed the indexing implementation in both buildIndex() and
traverseParents(). Duane pointed out that the incorrect parent node ids
were being indexed in xml_path_index, causing some stylesheets to render
metadata incorrectly. I've changed buildindex() to index the correct parent id,
and have changed traverseParents() to only index paths that actually contain
node data (some TEXT nodes exist with empty data).

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
1315 1315
                    updateNodeIndex(dbConn, pathList);
1316 1316
                } else if ( currentNode.getNodeType().equals("TEXT") ) {
1317 1317
                  
1318
                  // Set the parent node's nodedata and nodedatanumerical to
1319
                  // that of the leaf TEXT node being processed, and then
1320
                  // traverse the parents starting from the parent node.  The
1321
                  // xml_path_index table will be populated with ELEMENT paths
1322
                  // with TEXT nodedata (since it's modeled this way in the DOM)
1318
                  // A non-empty TEXT node represents the node data of its
1319
                  // parent ELEMENT node.  Traverse the parents starting from 
1320
                  // the TEXT node.  The xml_path_index table will be populated 
1321
                  // with ELEMENT paths with TEXT nodedata (since it's modeled 
1322
                  // this way in the DOM)
1323 1323
                  NodeRecord parentNode = 
1324 1324
                   (NodeRecord) nodeRecordMap.get(new Long(currentNode.getParentNodeId()));
1325
                  if ( parentNode.getNodeType().equals("ELEMENT") &&
1326
                       !currentNode.getNodeData().equals("") ) {
1327
                    parentNode.setNodeData(currentNode.getNodeData());
1328
                    parentNode.setNodeDataNumerical(currentNode.getNodeDataNumerical());
1325

  
1326
                  if ( parentNode.getNodeType().equals("ELEMENT") ) {
1329 1327
                    
1328
                    currentNode.setNodeType(parentNode.getNodeType());
1329
                    currentNode.setNodeName("");
1330
                    logMetacat.debug("Converted node " + currentNode.getNodeId() + 
1331
                      " to type " + parentNode.getNodeType());
1332
                    
1330 1333
                  	traverseParents(nodeRecordMap, rootNodeId,
1331 1334
                                    currentNode.getNodeId(),
1332
                                    parentNode.getNodeId(), 
1333
                                    "", pathList, pathsFound);  
1334
                  } 
1335
                                    currentNode.getNodeId(),
1336
                                    "", pathList, pathsFound);
1337
                  }
1335 1338
                }
1336 1339
                // Lastly, update the xml_path_index table
1337 1340
                if(!pathsFound.isEmpty()){
......
1396 1399
        String leafData = leafRecord.getNodeData();
1397 1400
        float leafDataNumerical = leafRecord.getNodeDataNumerical();
1398 1401
        
1399
        if (current.getNodeType().equals("ELEMENT") ||
1402
        if ( current.getNodeType().equals("ELEMENT") ||
1400 1403
            current.getNodeType().equals("ATTRIBUTE") ) {
1401 1404
        	  
1402 1405
        	  // process leaf node xpaths
......
1405 1408
                    currentName = "@" + currentName;
1406 1409
                }
1407 1410
                logMetacat.debug("A: " + currentName +"\n");
1408
                if ( !currentName.equals("") || !currentName.equals(null) ) {
1409
                  pathList.put(currentName, new PathIndexEntry(leafNodeId,
1410
                      currentName, docid, doctype, parentId));  
1411
                if ( currentName != null ) {
1412
                  if ( !currentName.equals("") ) {
1413
                    pathList.put(currentName, new PathIndexEntry(leafNodeId,
1414
                      currentName, docid, doctype, parentId));
1415
                  }
1411 1416
                }
1412 1417
                if( MetaCatUtil.pathsForIndexing.contains(currentName) &&
1413
                    !leafData.equals("") ){
1418
                    leafData.trim().length() != 0 ){
1414 1419
                	logMetacat.debug("paths found for indexing: " + currentName);
1415 1420
                	pathsFoundForIndexing.put(currentName, new PathIndexEntry(
1416 1421
                            leafNodeId, currentName, docid, parentId, leafData,
......
1419 1424
            }
1420 1425
            
1421 1426
            // process relative xpaths
1422
            if ( !currentName.equals("") || !currentName.equals(null) ) {
1427
            if ( !currentName.equals("") ) {
1423 1428
              currentName = "/" + currentName;
1424 1429
              currentName = currentName + children;
1425 1430
            }
......
1429 1434
            }
1430 1435
            String path = current.getNodeName() + children;
1431 1436
            
1432
            if (!children.equals("")) {
1437
            if ( !children.equals("") ) {
1433 1438
                logMetacat.debug("B: " + path +"\n");
1434 1439
                pathList.put(path, new PathIndexEntry(leafNodeId, path, docid,
1435 1440
                    doctype, parentId));
1436 1441
                if( MetaCatUtil.pathsForIndexing.contains(path) &&
1437
                    !leafData.equals("") ){
1442
                    leafData.trim().length() != 0 ){
1438 1443
                	logMetacat.debug("paths found for indexing: " + currentName);
1439 1444
                	pathsFoundForIndexing.put(path, new PathIndexEntry(
1440 1445
                            leafNodeId, path, docid, parentId, leafData,
......
1444 1449
            // process absolute xpaths
1445 1450
            if (id == rootNodeId) {
1446 1451
                String fullPath = "";
1447
                if ( !path.equals("") || !currentName.equals(null) ) {
1452
                if ( !path.equals("") ) {
1448 1453
                  fullPath = '/' + path;
1449 1454
                }
1450 1455
                logMetacat.debug("C: " + fullPath +"\n");
1451 1456
                pathList.put(fullPath, new PathIndexEntry(leafNodeId, fullPath,
1452 1457
                    docid, doctype, parentId));
1453 1458
                if( MetaCatUtil.pathsForIndexing.contains(fullPath) &&
1454
                   !leafData.equals("") ){
1459
                   leafData.trim().length() != 0 ){
1455 1460
                	logMetacat.debug("paths found for indexing: " + currentName);
1456 1461
                	pathsFoundForIndexing.put(fullPath, new PathIndexEntry(
1457 1462
                            leafNodeId, fullPath, docid, parentId, leafData,
......
1571 1576
        Iterator it = pathsFound.values().iterator();
1572 1577
         while (it.hasNext()) {
1573 1578
             PathIndexEntry entry = (PathIndexEntry)it.next();
1574

  
1575 1579
             pstmt.setString(1,entry.docid);
1576 1580
             pstmt.setString(2, entry.path);
1577 1581
             pstmt.setString(3, entry.nodeData);

Also available in: Unified diff