Changeset 2149


Ignore:
Timestamp:
2001-03-09T19:09:48+13:00 (23 years ago)
Author:
say1
Message:

resolved issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java

    r2148 r2149  
    186186  /** respond to the user pressing the Search button */
    187187
    188 public void actionPerformed(ActionEvent e) {
    189       if (e.getSource() == searchButton ) { //assume only searchButton generates events
    190        System.out.println("Search button pressed in SearchPanel");
    191        //send query to collection
    192        NzdlQuery nzdlQuery = new NzdlQuery( searchTextField.getText() );
    193        // return the first numResults that match
    194        //query.setEndResults( 15 );
    195        // "-1" means consider all the documents that match
    196        nzdlQuery.setMaxDocs( -1 );
    197        String collectionName = collectionList.getSelectedItem().toString();
    198        NzdlRequest request = new NzdlRequest( nzdlQuery );
    199        NzdlResponse response = new NzdlResponse( );
    200        csModel.getNzdlService().service( collectionName, request, response ); //nzdl object ????
    201            NzdlResultSet results = response.getResultSet();
    202        java.util.List docIDs = results.getDocumentIDs();
    203        // paired collection of docIDs and Titles - but as Sets!
    204        Map titleMetaData = csModel.getNzdlService().getMetaData( collectionName, docIDs, "Title" );
    205        // created a paired collection of docIDs and Titles - as simple Strings!
    206        HashMap titleMap = new HashMap();
    207        for (ListIterator i = docIDs.listIterator(); i.hasNext(); ) {
    208            String docID = (String) i.next();
    209            Set titleSet = (Set) titleMetaData.get( docID );
    210            ArrayList titleList = new ArrayList(titleSet);
    211            // use the first title as *the* title
    212            titleMap.put(docID, titleList.get(0));
    213        } // end for
    214        // update the results list
    215        // empty previous results List
    216        csModel.clearResults();
    217        // System.err.println("Size of docIDs = " + docIDs.size());
    218        if (docIDs.size() == 0 ) { // no real results
    219            csModel.addResult(new Result(Result.FAKE_RESULT, "", ""));
    220        }
    221        else { // there are some results
    222            Iterator docIDsIterator = docIDs.iterator();
    223            while (docIDsIterator.hasNext()) {
    224            String resultDocID =  (String) docIDsIterator.next();
    225            //System.err.println("Adding result");
    226            csModel.addResult(new Result((String)titleMap.get(resultDocID), resultDocID, collectionName ));
    227            } //end while
    228        } // end else
    229            // default to showing the top ranked document
     188  public void actionPerformed(ActionEvent e) {
     189    if (e.getSource() == searchButton ) { //assume only searchButton generates events
     190      System.out.println("Search button pressed in SearchPanel");
     191      //send query to collection
     192      NzdlQuery nzdlQuery = new NzdlQuery( searchTextField.getText() );
     193      // return the first numResults that match
     194      //query.setEndResults( 15 );
     195      // "-1" means consider all the documents that match
     196      nzdlQuery.setMaxDocs( -1 );
     197      String collectionName = collectionList.getSelectedItem().toString();
     198      NzdlRequest request = new NzdlRequest( nzdlQuery );
     199      NzdlResponse response = new NzdlResponse( );
     200      csModel.getNzdlService().service( collectionName, request, response ); //nzdl object ????
     201      NzdlResultSet results = response.getResultSet();
     202      java.util.List docIDs = results.getDocumentIDs();
     203      // paired collection of docIDs and Titles - but as Sets!
     204      Map titleMetaData = csModel.getNzdlService().getMetaData( collectionName, docIDs, "Title" );
     205      // created a paired collection of docIDs and Titles - as simple Strings!
     206      HashMap titleMap = new HashMap();
     207      for (ListIterator i = docIDs.listIterator(); i.hasNext(); ) {
     208    String docID = (String) i.next();
     209    Set titleSet = (Set) titleMetaData.get( docID );
     210    ArrayList titleList = new ArrayList(titleSet);
     211    // use the first title as *the* title
     212    titleMap.put(docID, titleList.get(0));
     213      } // end for
     214      // update the results list
     215      // empty previous results List
     216      csModel.clearResults();
     217      // System.err.println("Size of docIDs = " + docIDs.size());
     218      if (docIDs.size() == 0 ) { // no real results
     219    csModel.addResult(new Result(Result.FAKE_RESULT, "", ""));
     220      }
     221      else { // there are some results
     222    Iterator docIDsIterator = docIDs.iterator();
     223    while (docIDsIterator.hasNext()) {
     224      String resultDocID =  (String) docIDsIterator.next();
     225      //System.err.println("Adding result");
     226      csModel.addResult(new Result((String)titleMap.get(resultDocID), resultDocID, collectionName ));
     227    } //end while
     228      } // end else
     229      // default to showing the top ranked document
    230230      if (docIDs.size() > 0)
    231            resultsList.setSelectedIndex(0);
    232        } // end if
     231    resultsList.setSelectedIndex(0);
     232    } // end if
     233    else {
     234      System.out.println("unknown Action event in SearchPanel");
     235    }
     236  } //end actionPerformed
     237
     238  /** handles selection events in the results list so that when the
     239      user selects a new title (say) the document contents is
     240      automatically displayed in the main panel */
     241
     242  class ResultListSelectionHandler implements ListSelectionListener {
     243    public void valueChanged(ListSelectionEvent e) {
     244      // get the result object from the SelectedIndex
     245      // assume we only get here with events from resultsList
     246      Result result =  (Result) resultsList.getSelectedValue();
     247      if (result.toString() == Result.FAKE_RESULT) {
     248    dataTextArea.setText(null);
     249    //System.err.println("no results");
     250      }
    233251      else {
    234        System.out.println("unknown Action event in SearchPanel");
    235       }
    236  } //end actionPerformed
    237 
    238   /** handles selection events in the results list so that when the
    239        user selects a new title (say) the document contents is
    240        automatically displayed in the main panel */
    241 
    242  class ResultListSelectionHandler implements ListSelectionListener {
    243      public void valueChanged(ListSelectionEvent e) {
    244      // get the result object from the SelectedIndex
    245      // assume we only get here with events from resultsList
    246      Result result =  (Result) resultsList.getSelectedValue();
    247      if (result.toString() == Result.FAKE_RESULT) {
    248          dataTextArea.setText(null);
    249          //System.err.println("no results");
    250      }
    251      else {
    252          //get the document content from the result object
    253          // use a String for the moment to hold the contents
    254          // should cache document contents here to speed access
    255          String documentContents = csModel.getNzdlService().getDocument(result.getCollectionName(),  result.getDocID());
    256          documentContents = DOC_HEADER + documentContents + DOC_FOOTER;
    257          dataTextArea.setText(documentContents);
    258          dataTextArea.setCaretPosition(0);
    259      }
    260      } //end valueChanged
    261 }//end ResultListSelectionHandler
    262 >>>>>>> 1.4
     252    //get the document content from the result object
     253    // use a String for the moment to hold the contents
     254    // should cache document contents here to speed access
     255    String documentContents = csModel.getNzdlService().getDocument(result.getCollectionName(),  result.getDocID());
     256    documentContents = DOC_HEADER + documentContents + DOC_FOOTER;
     257    dataTextArea.setText(documentContents);
     258    dataTextArea.setCaretPosition(0);
     259      }
     260    } //end valueChanged
     261  }//end ResultListSelectionHandler
     262
    263263
    264264
Note: See TracChangeset for help on using the changeset viewer.