Changeset 2147
- Timestamp:
- 2001-03-09T17:20:32+13:00 (23 years ago)
- Location:
- trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/Result.java
r2143 r2147 37 37 private String collectionName; 38 38 39 40 public final static String FAKE_RESULT = "No results returned"; 41 39 42 // related query 40 43 // time, person, collection etc … … 54 57 public String toString () 55 58 { 56 return ( resultTitle);59 return resultTitle; 57 60 } 58 61 public String getDocID() -
trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java
r2145 r2147 179 179 } 180 180 181 public void setCollectionIndex(int index) { 182 183 collectionList.setSelectedIndex(index); 184 185 } 186 187 188 /** respond to the user pressing the Search button */ 189 190 public void actionPerformed(ActionEvent e) { 191 Object source = e.getSource(); 192 if (source == searchButton ) { //assume only searchButton generates events 193 System.out.println("Search button pressed in SearchPanel"); 194 //send query to collection 195 NzdlQuery nzdlQuery = new NzdlQuery( searchTextField.getText() ); 196 // return the first numResults that match 197 //query.setEndResults( 15 ); 198 // "-1" means consider all the documents that match 199 nzdlQuery.setMaxDocs( -1 ); 200 String collectionName = collectionList.getSelectedItem().toString(); 201 NzdlRequest request = new NzdlRequest( nzdlQuery ); 202 NzdlResponse response = new NzdlResponse( ); 203 csModel.getNzdlService().service( collectionName, request, response ); //nzdl object ???? 204 NzdlResultSet results = response.getResultSet(); 205 java.util.List docIDs = results.getDocumentIDs(); 206 // paired collection of docIDs and Titles - but as Sets! 207 Map titleMetaData = csModel.getNzdlService().getMetaData( collectionName, docIDs, "Title" ); 208 // created a paired collection of docIDs and Titles - as simple Strings! 209 HashMap titleMap = new HashMap(); 210 for (ListIterator i = docIDs.listIterator(); i.hasNext(); ) { 211 String docID = (String) i.next(); 212 Set titleSet = (Set) titleMetaData.get( docID ); 213 ArrayList titleList = new ArrayList(titleSet); 214 // String documentContents = csModel.getNzdlService().getDocument(collectionName, docID); 215 //titleMap.put(docID, titleSet.toString()); // 216 titleMap.put(docID, titleList.get(0)); // use the first title as *the* title 217 } // end for 218 // update resultsListModel 219 // empty previous results List 220 csModel.clearResults(); 221 System.err.println("Size of docIDs = " + docIDs.size()); 222 Iterator docIDsIterator = docIDs.iterator(); 223 while (docIDsIterator.hasNext()) { 224 String resultDocID = (String) docIDsIterator.next(); 225 Result result = new Result( (String)titleMap.get(resultDocID), resultDocID, collectionName ); 226 System.err.println("Adding result"); 227 csModel.addResult(result); 228 } //end while 229 // default to showing the top ranked document 230 if (docIDs.size() > 0) 231 resultsList.setSelectedIndex(0); 232 } // end if 233 else { 234 System.out.println("unknown Action event in SearchPanel"); 235 } 236 } //end actionPerformed 237 238 239 240 /** 241 * handles selection events in the results list so that when 242 * the user selects a new title (say) the document contents 243 * is automatically displayed in the main panel 244 */ 245 246 class ResultListSelectionHandler implements ListSelectionListener { 247 public void valueChanged(ListSelectionEvent e) { 248 //get the result object from the SelectedIndex 249 Result result = (Result) resultsList.getSelectedValue(); 250 // should check here to see if anything was actually selected ! 251 //get the document content from the result object 252 // use a String for the moment to hold the contents 253 String documentContents = csModel.getNzdlService().getDocument(result.getCollectionName(), result.getDocID()); 254 dataTextArea.setText(documentContents); 255 dataTextArea.setCaretPosition(0); 256 } //end valueChanged 257 }//end ResultListSelectionHandler 181 182 183 /* respond to the user pressing the Search button */ 184 185 public void actionPerformed(ActionEvent e) { 186 if (e.getSource() == searchButton ) { //assume only searchButton generates events 187 System.out.println("Search button pressed in SearchPanel"); 188 //send query to collection 189 NzdlQuery nzdlQuery = new NzdlQuery( searchTextField.getText() ); 190 // return the first numResults that match 191 //query.setEndResults( 15 ); 192 // "-1" means consider all the documents that match 193 nzdlQuery.setMaxDocs( -1 ); 194 String collectionName = collectionList.getSelectedItem().toString(); 195 NzdlRequest request = new NzdlRequest( nzdlQuery ); 196 NzdlResponse response = new NzdlResponse( ); 197 csModel.getNzdlService().service( collectionName, request, response ); //nzdl object ???? 198 NzdlResultSet results = response.getResultSet(); 199 java.util.List docIDs = results.getDocumentIDs(); 200 // paired collection of docIDs and Titles - but as Sets! 201 Map titleMetaData = csModel.getNzdlService().getMetaData( collectionName, docIDs, "Title" ); 202 // created a paired collection of docIDs and Titles - as simple Strings! 203 HashMap titleMap = new HashMap(); 204 for (ListIterator i = docIDs.listIterator(); i.hasNext(); ) { 205 String docID = (String) i.next(); 206 Set titleSet = (Set) titleMetaData.get( docID ); 207 ArrayList titleList = new ArrayList(titleSet); 208 // use the first title as *the* title 209 titleMap.put(docID, titleList.get(0)); 210 } // end for 211 // update the results list 212 // empty previous results List 213 csModel.clearResults(); 214 // System.err.println("Size of docIDs = " + docIDs.size()); 215 if (docIDs.size() == 0 ) { // no real results 216 csModel.addResult(new Result(Result.FAKE_RESULT, "", "")); 217 } 218 else { // there are some results 219 Iterator docIDsIterator = docIDs.iterator(); 220 while (docIDsIterator.hasNext()) { 221 String resultDocID = (String) docIDsIterator.next(); 222 //System.err.println("Adding result"); 223 csModel.addResult(new Result((String)titleMap.get(resultDocID), resultDocID, collectionName )); 224 } //end while 225 } // end else 226 // default to showing the top ranked document 227 resultsList.setSelectedIndex(0); 228 } // end if 229 else { 230 System.out.println("unknown Action event in SearchPanel"); 231 } 232 } //end actionPerformed 233 234 235 236 /* handles selection events in the results list so that when the 237 user selects a new title (say) the document contents is 238 automatically displayed in the main panel */ 239 240 class ResultListSelectionHandler implements ListSelectionListener { 241 public void valueChanged(ListSelectionEvent e) { 242 // get the result object from the SelectedIndex 243 // assume we only get here with events from resultsList 244 Result result = (Result) resultsList.getSelectedValue(); 245 if (result.toString() == Result.FAKE_RESULT) { 246 dataTextArea.setText(null); 247 //System.err.println("no results"); 248 } 249 else { 250 //get the document content from the result object 251 // use a String for the moment to hold the contents 252 // should cache document contents here to speed access 253 String documentContents = csModel.getNzdlService().getDocument(result.getCollectionName(), result.getDocID()); 254 dataTextArea.setText(documentContents); 255 dataTextArea.setCaretPosition(0); 256 } 257 } //end valueChanged 258 }//end ResultListSelectionHandler 258 259 259 260
Note:
See TracChangeset
for help on using the changeset viewer.