Changeset 3766

Show
Ignore:
Timestamp:
25.02.2003 15:18:02 (17 years ago)
Author:
mdewsnip
Message:

Support for modified query result format (changes to "numDocsMatched" and query term information).

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java

    r3753 r3766  
    148148    // System.out.println("Query response: " + converter_.getString(mr_query_response)); 
    149149 
    150     Element query_result_metadata_list = (Element) GSXML.getNodeByPath(mr_query_response, "response/content/metadataList"); 
     150    Element query_result_metadata_list = (Element) GSXML.getNodeByPath(mr_query_response, "response/metadataList"); 
    151151    if (query_result_metadata_list == null) { 
    152152        System.err.println("Warning: No query result metadata.\n"); 
    153153    } 
    154     else { 
    155         System.out.println("Query result metadata: " + converter_.getString(query_result_metadata_list) + "\n"); 
     154 
     155    Element query_term_info_list = (Element) GSXML.getNodeByPath(mr_query_response, "response/content/termList"); 
     156    if (query_term_info_list == null) { 
     157        System.err.println("Warning: No query term information.\n"); 
    156158    } 
    157159 
     
    210212    // If there is some metadata about the query results, add it in 
    211213    if (query_result_metadata_list != null) { 
     214        result_response.appendChild(query_result_metadata_list); 
     215    } 
     216    // If there is some metadata about the query results, add it in 
     217    if (query_term_info_list != null) { 
    212218        Element result_content = (Element) GSXML.getChildByTagName(result_response, 
    213219                                       GSXML.CONTENT_ELEM); 
    214         result_content.appendChild(query_result_metadata_list); 
     220        result_content.appendChild(query_term_info_list); 
    215221    } 
    216222 
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGSearch.java

    r3755 r3766  
    288288    String textdir = GSFile.collectionTextPath(cluster_name_); 
    289289    String indexpath = GSFile.collectionIndexPath(cluster_name_, index); 
    290     System.out.println("Base directory: " + basedir); 
    291     System.out.println("Text directory: " + textdir); 
    292     System.out.println("Index path: " + indexpath); 
    293290 
    294291    // set the mg query parameters to the values the user has specified 
     
    307304        // no docs found 
    308305        System.out.println("No results found...\n"); 
    309         // return result; 
    310     } 
    311  
    312     // create a documentList element 
     306    } 
     307 
     308    // Create a metadata list to store information about the query results 
     309    Element metadata_list = GSXML.addMetaList(doc_, result); 
     310 
     311    // Add a metadata element specifying the number of matching documents 
     312    Element num_matches_elem = doc_.createElement(GSXML.METADATA_ELEM); 
     313    num_matches_elem.setAttribute(GSXML.NAME_ATT, "numDocsMatched"); 
     314    num_matches_elem.setAttribute(GSXML.VALUE_ATT, "" + totalDocs); 
     315    metadata_list.appendChild(num_matches_elem); 
     316    // System.out.println("Metadata list: " + converter_.getString(metadata_list)); 
     317 
     318    // Response content: documents and terms 
    313319    Element c = doc_.createElement(GSXML.CONTENT_ELEM); 
    314320    result.appendChild(c); 
    315  
    316     // Create a metadata list to store information about the query results 
    317     Element metadata_list = GSXML.addMetaList(doc_, c); 
    318  
    319     // Add a metadata element to the result content specifying the number of matches 
    320     GSXML.addMetadata(doc_, metadata_list, "numMatchingDocs", "" + totalDocs); 
    321     System.out.println("Metadata list: " + converter_.getString(metadata_list)); 
    322  
    323     // get the terms out, and add to query result metadata 
    324     Vector terms = mqr.getTerms(); 
    325     if (terms.size() == 0) { 
    326         // no terms found 
    327         System.out.println("No query term information available...\n"); 
    328     } 
    329     else { 
    330         for (int t = 0; t < terms.size(); t++) { 
    331         String term = ((MGTermInfo) terms.elementAt(t)).term_; 
    332         long term_freq = ((MGTermInfo) terms.elementAt(t)).term_freq_; 
    333         Element metadata_elem = doc_.createElement(GSXML.METADATA_ELEM); 
    334         metadata_elem.setAttribute(GSXML.TYPE_ATT, "term"); 
    335         metadata_elem.setAttribute(GSXML.NAME_ATT, term); 
    336         metadata_elem.setAttribute(GSXML.VALUE_ATT, "" + term_freq); 
    337         metadata_list.appendChild(metadata_elem); 
    338         } 
    339     } 
    340321 
    341322    Element document_list = doc_.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER); 
     
    345326        long docnum = ((MGDocInfo) docs.elementAt(d)).num_; 
    346327        String id = gdbm_src_.docnum2Oid(docnum); 
     328        System.out.println("Docnum: " + docnum + " ID: " + id); 
    347329        Node no = GSXML.createDocumentElement(doc_, id); 
    348330        document_list.appendChild(no); 
     331    } 
     332 
     333    Element term_list = doc_.createElement(GSXML.TERM_ELEM+GSXML.LIST_MODIFIER); 
     334    c.appendChild(term_list); 
     335    // get the terms out, and add to query result metadata 
     336    Vector terms = mqr.getTerms(); 
     337    for (int t = 0; t < terms.size(); t++) { 
     338        String term = ((MGTermInfo) terms.elementAt(t)).term_; 
     339        long term_freq = ((MGTermInfo) terms.elementAt(t)).term_freq_; 
     340        int stem_method = ((MGTermInfo) terms.elementAt(t)).stem_method_; 
     341 
     342        Element term_elem = doc_.createElement(GSXML.TERM_ELEM); 
     343        term_elem.setAttribute(GSXML.NAME_ATT, term); 
     344        term_elem.setAttribute("count", "" + term_freq); 
     345        term_elem.setAttribute("stem", "" + stem_method); 
     346        term_list.appendChild(term_elem); 
    349347    } 
    350348