Changeset 8439 for trunk/gsdl3/src


Ignore:
Timestamp:
2004-11-03T14:46:37+13:00 (20 years ago)
Author:
kjdon
Message:

when creating doc nodes, now we choose hierarchy or simple based on whether there is a section structure in the database. we used to always change doc ids that matched the whole structure to be the first section id, eg 20041102:1 to 20041102:1-1. this is now only done for hierarchical docs, not for simple docs.

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/service
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGRetrieve.java

    r7312 r8439  
    164164        //ystem.out.println("translated id = "+doc_id);
    165165        }
    166         if (GS3OID.isDocTop(doc_id)) {
    167         System.out.println("adding the structure bit to doc id");
    168         doc_id = GS3OID.createOID(doc_id, "1");
     166        if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) {
     167        // if we have a whole doc id, and the document is hierarchical,
     168        // we want to change the id to be the top id of the section
     169        // hierarchy
     170            doc_id = GS3OID.createOID(doc_id, "1");
    169171        }
    170         String doc_num = this.database.OID2MGNum(doc_id);
    171        
    172         //long doc_num = this.gdbm_src.oid2Docnum(doc_id);
    173         System.out.println("mg doc num = "+doc_num);
     172        String doc_num = this.database.OID2MGNum(doc_id);       
    174173        // doc nums have the index prefixed
    175174        doc_num = doc_num.substring(doc_num.indexOf(".")+1);
    176175        int doc_int = Integer.parseInt(doc_num);
    177         System.out.println("actual mg doc num="+doc_int);
     176       
    178177        String doc_content = "";
    179178        try {
    180           doc_content = this.mg_src.getDocument(basedir, textdir, doc_int);
     179        doc_content = this.mg_src.getDocument(basedir, textdir, doc_int);
    181180        } catch (Exception e) {
    182           System.out.println("exception happended with mg_src.getDocument()");
    183           doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n";
     181        System.out.println("exception happended with mg_src.getDocument()");
     182        doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n";
    184183        }
    185184        //ystem.out.println("Doc content: " + doc_content + "|");
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGSearch.java

    r7312 r8439  
    144144        // hack !!!
    145145        if (doc_id.endsWith("-All")) {
    146         System.err.print("replacing doc id "+doc_id+" with ");
    147         doc_id=doc_id.replaceAll("All","1");
    148         System.err.println(doc_id);
     146        // get rid of the All bit
     147        doc_id = doc_id.substring(0,doc_id.length()-4);
     148        //doc_id=doc_id.replaceAll("All","1");
    149149        }
    150150       
    151         //String doc_id = this.gdbm_src.docnum2Oid(docnum);
    152151        Element doc_node = createDocumentNodeElement(doc_id);
    153152        document_list.appendChild(doc_node);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Retrieve.java

    r7312 r8439  
    313313     * child is true is it definitely is a child of something - just for efficiency purposes */
    314314    protected Element createDocNode(String node_id, boolean parent, boolean child) {
    315 //      Element node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    316 //      node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
    317 //      node.setAttribute(GSXML.NODE_ID_ATT, node_id);
    318 //      return node;
    319315   
    320316    Element node;
    321317    if (isClassifier(node_id)) {
    322318        node = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
     319        node.setAttribute(GSXML.NODE_ID_ATT, node_id);
     320        return node;
     321       
    323322        //String childtype = info.getInfo("childtype");
    324323        //String orientation="";
     
    329328        //}
    330329        //node.setAttribute(GSXML.CLASS_NODE_ORIENTATION_ATT, orientation);
     330    }
     331    // a doc node
     332    node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
     333    node.setAttribute(GSXML.NODE_ID_ATT, node_id);
     334    boolean hierarchical = false;
     335    if (parent || child || !GS3OID.isDocTop(node_id) || database.isHierarchicalDocument(node_id) ) {
     336        hierarchical = true;
     337    }
     338    // what about paged???
     339    if (!hierarchical) {
     340        // a simple document
     341        node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
    331342    } else {
    332        
    333         node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    334         node.setAttribute(GSXML.DOC_TYPE_ATT, "hierarchy"); // need to work this out dynamically
    335 
    336         if (GS3OID.isTop(node_id)) {
     343        // a hierarchical doc
     344        node.setAttribute(GSXML.DOC_TYPE_ATT, "hierarchy");
     345       
     346       
     347        if (!child && GS3OID.isTop(node_id)) {
    337348        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT);
    338         } else if (database.documentHasChildren(node_id)){
     349        } else if (parent || database.documentHasChildren(node_id)){
    339350        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERIOR);
    340351        } else {
    341352        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
    342353        }
    343 //          String top_id = GS3OID.getTop(node_id);
    344 //          boolean is_top = (top_id.equals(node_id) ? true : false);
    345    
    346 //          String children = info.getInfo("contains");
    347 //          boolean is_leaf = (children.equals("") ? true : false);
    348        
    349 //          // set teh node type att
    350 //          if (is_top) {
    351 //          node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT);
    352 //          } else if (is_leaf) {
    353 //          node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
    354 //          } else {
    355 //          node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERIOR);
    356 //          }
    357 
    358 //          // set teh doc type att
    359 //          if (is_top && is_leaf) { // a single section document
    360 //          node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
    361        
    362 //          } else {
    363        
    364 //          if (!is_top) { // we need to look at the top info
    365 //              info = this.gdbm_src.getInfo(top_id);
    366 //          }
    367        
    368 //          String childtype = info.getInfo("childtype");
    369 //          if (childtype.equals("Paged")) {
    370 //              node.setAttribute(GSXML.DOC_TYPE_ATT, "paged");
    371 //          } else {
    372 //              node.setAttribute(GSXML.DOC_TYPE_ATT, "hierarchy");
    373 //          }
    374 //          }
    375        
    376     }
    377     node.setAttribute(GSXML.NODE_ID_ATT, node_id);
     354    }
    378355    return node;
    379 
    380     }
     356    }   
     357   
    381358    /** Returns the parent of a specified documentID, or null if none exists */
    382359    protected Element getParent(String doc_id)
     
    414391        for (int i=0; i<documents.size(); i++) {
    415392        String child_id = (String) documents.get(i);
    416         Element child = createDocNode(child_id, false, true);
     393        Element child = createDocNode(child_id, false, false);
    417394        doc.appendChild(child);
    418395        }
     
    577554        doc_id = GS3OID.translateOID(doc_id);
    578555        }
     556        // this doesn't work for single section docs
     557        // but we shouldn't be asking for structure from them
    579558        if (type==DOCUMENT && GS3OID.isDocTop(doc_id)) {
    580         doc_id = GS3OID.createOID(doc_id, "1");
     559            doc_id = GS3OID.createOID(doc_id, "1");
    581560        }
    582561        // Add the document to the list
     
    715694        param = (Element) param.getNextSibling();
    716695    }
    717    
    718696    Element node_list = this.doc.createElement(node_name+GSXML.LIST_MODIFIER);
    719697    result.appendChild(node_list);
     
    724702        System.err.println("Error: DocumentMetadataRetrieve request had no "+node_name+"List.\n");
    725703        return result;
    726     }
    727    
     704    } 
     705
    728706    NodeList request_nodes = request_node_list.getChildNodes();
    729707    for (int i = 0; i < request_nodes.getLength(); i++) {
    730708        Element request_node = (Element) request_nodes.item(i);
    731709        String node_id = request_node.getAttribute(GSXML.NODE_ID_ATT);
    732 
    733710        if (GS3OID.needsTranslating(node_id)) {
    734711        //node_id = this.gdbm_src.translateOID(node_id);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Search.java

    r7993 r8439  
    271271    Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    272272    doc_node.setAttribute(GSXML.NODE_ID_ATT, node_id);
    273 
    274     String top_id = OID.getTop(node_id);
    275     boolean is_top = (top_id.equals(node_id) ? true : false);
    276    
    277     doc_node.setAttribute(GSXML.DOC_TYPE_ATT, "hierarchy");
    278 
    279     if (GS3OID.isTop(node_id)) {
    280         doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT);
    281     } else if (database.documentHasChildren(node_id)){
    282         doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERIOR);
     273   
     274    if (GS3OID.isDocTop(node_id) && !database.isHierarchicalDocument(node_id) ) {
     275        // a simple document
     276        doc_node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
    283277    } else {
    284         doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
     278        // what about paged??
     279        doc_node.setAttribute(GSXML.DOC_TYPE_ATT, "hierarchy");
     280       
     281        if (GS3OID.isTop(node_id)) {
     282        doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT);
     283        } else if (database.documentHasChildren(node_id)){
     284        doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERIOR);
     285        } else {
     286        doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
     287        }
    285288    }
    286289   
    287290    return doc_node;
    288291    }
    289 //      DBInfo info = this.gdbm_src.getInfo(node_id);
    290 //      if (info == null) { // make it up - cant query the gdbm db
    291 //          doc_node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
    292 //          return doc_node;
    293 //      }
    294 //      String children = info.getInfo("contains");
    295 //      boolean is_leaf = (children.equals("") ? true : false);
    296 
    297 //      // check for simple doc types
    298 //      if (is_top && is_leaf) { // a single section document
    299 //          doc_node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
    300 //          return doc_node;
    301 //      }
    302 //      // set teh node type att
    303 //      if (is_top) {
    304 //          doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT);
    305 //      } else if (is_leaf) {
    306 //          doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
    307 //      } else {
    308 //          doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERIOR);
    309 //      }
    310    
    311 //      if (!is_top) { // we need to look at the top info
    312 //          info = this.gdbm_src.getInfo(top_id);
    313 //      }
    314 
    315 //      String childtype = info.getInfo("childtype");
    316 //      if (childtype.equals("Paged")) {
    317 //          doc_node.setAttribute(GSXML.DOC_TYPE_ATT, "paged");
    318 //      } else {
    319 //          doc_node.setAttribute(GSXML.DOC_TYPE_ATT, "hierarchy");
    320 //      }
    321 //      return doc_node;
    322 //      }
    323    
    324     /** returns the document type of a node - if the node is a subnode, it returns teh type of teh top document node. for now, only does paged and hierarchical, but eventually will have more types */
    325 //      protected String getDocType(String node_id) {
    326 
    327 //      String doc_id = OID.getTop(node_id);
    328 //      DBInfo info = this.gdbm_src.getInfo(doc_id);
    329 //      String child_type = info.getInfo("childtype");
    330 //      if (child_type.equals("Paged")) {
    331 //          return "paged";
    332 //      }
    333 //      return "hierarchy";
    334    
    335 //      }
    336 
    337     /** Returns true if the OID specifies a leaf node, false otherwise
    338     Note: this makes a request to the GDBM database so it may not be cheap */
    339 //      protected boolean isLeafNode(String oid)
    340 //      {
    341 //      DBInfo info = this.gdbm_src.getInfo(oid);
    342 //      String children = info.getInfo("contains");
    343 //      return (children.equals(""));
    344 //      }
    345 
    346292
    347293    /** Process a text query - implemented by concrete subclasses */
Note: See TracChangeset for help on using the changeset viewer.