Changeset 313 for trunk/src/org/expeditee/agents/SearchGreenstone.java
- Timestamp:
- 09/23/08 15:05:41 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/agents/SearchGreenstone.java
r312 r313 1 1 package org.expeditee.agents; 2 2 3 import java.util.Collections;4 3 import java.util.Enumeration; 5 4 import java.util.HashMap; 5 import java.util.Map; 6 6 import java.util.Vector; 7 7 … … 12 12 import org.expeditee.greenstone.ResultDocument; 13 13 import org.expeditee.gui.AttributeValuePair; 14 import org.expeditee.gui.DisplayIO; 14 15 import org.expeditee.gui.Frame; 15 16 import org.expeditee.gui.FrameCreator; 16 17 import org.expeditee.gui.FrameGraphics; 18 import org.expeditee.gui.FrameMouseActions; 19 import org.expeditee.gui.MessageBay; 17 20 import org.expeditee.items.Text; 18 21 19 22 public class SearchGreenstone extends SearchAgent { 20 23 24 private static String _fullCaseSearchQuery = null; 25 21 26 private static boolean _doCasefolding = true; 22 27 … … 27 32 private static String _maxResults = "10"; 28 33 34 private static boolean _showAbstract = false; 35 private static boolean _showKeywords = false; 36 private static boolean _showAuthors = false; 37 private static boolean _showDate = false; 38 39 private String _thisMaxResults = "10"; 40 29 41 private int _indexChoice = 1; 30 42 … … 35 47 private static String[] _indexKeys = { "TX", "TI", "JO", "BO", "CR", "KE" }; 36 48 37 protected static Vector<Result> _currentResultSet; 49 protected static Vector<Result> _currentResultSet = null; 50 51 private boolean _useLastSearchResults = false; 52 53 /** 54 * dateMap is a hash table. The keys are year values. the data associated 55 * with each key is a Vector of document IDs therefore, for the current 56 * result set you can get the set of years in which the results were 57 * published, and for each year you can get the set of documents published 58 * in that year 59 * 60 * If you want to introduce additional mappings (eg document written by 61 * authors) you should introduce additional structures here (HashMap used in 62 * the same way as dateMap will probably suffice 63 * 64 */ 65 protected static Map<String, Vector<String>> _dateMap = new HashMap<String, Vector<String>>(); 66 67 protected static Map<Integer, Vector<String>> _pageCountMap = new HashMap<Integer, Vector<String>>(); 68 69 protected static Map<String, String> _titleMap = new HashMap<String, String>(); 70 71 public SearchGreenstone(int resultsCount, String searchText) { 72 super(searchText); 73 _thisMaxResults = resultsCount + ""; 74 _fullCaseSearchQuery = searchText; 75 } 38 76 39 77 public SearchGreenstone(String searchText) { 40 78 super(searchText); 41 } 42 43 public SearchGreenstone(int resultsCount, String searchText) { 44 this(searchText); 45 _maxResults = resultsCount + ""; 79 _thisMaxResults = _maxResults; 80 _fullCaseSearchQuery = searchText; 81 } 82 83 public SearchGreenstone() { 84 super(null); 85 _useLastSearchResults = true; 46 86 } 47 87 … … 61 101 if (attribute.equals("campus")) 62 102 _locationChoice = 0; 63 if (attribute.equals("autoconnect"))103 else if (attribute.equals("autoconnect")) 64 104 connect(); 65 105 66 if (attribute.equals("maxresults")) {106 else if (attribute.equals("maxresults")) { 67 107 try { 68 108 _maxResults = avp.getValue(); … … 71 111 } 72 112 73 if (attribute.equals("dostemming"))113 else if (attribute.equals("dostemming")) 74 114 _doStemming = true; 115 else if (attribute.startsWith("showabstract")) 116 _showAbstract = true; 117 else if (attribute.startsWith("showauthor")) 118 _showAuthors = true; 119 else if (attribute.startsWith("showkeyword")) 120 _showKeywords = true; 121 else if (attribute.startsWith("showdate")) 122 _showDate = true; 75 123 } 76 124 } … … 83 131 @Override 84 132 protected Frame process(Frame frame) { 85 _results.setTitle("SearchGreenstone [" + _pattern + "]"); 86 87 connect(); 88 89 doQuery(_pattern); 133 String resultsTitle = this.getClass().getSimpleName() + "[" 134 + _fullCaseSearchQuery + "]"; 135 _results.setTitle(resultsTitle); 136 137 if (!_useLastSearchResults) { 138 connect(); 139 doQuery(_pattern); 140 } else if (_currentResultSet != null) { 141 Text newText = DisplayIO.getCurrentFrame().createNewText( 142 _fullCaseSearchQuery); 143 _clicked = newText; 144 FrameMouseActions.pickup(newText); 145 } 146 147 if (_currentResultSet == null) { 148 MessageBay.errorMessage("Could not find Greenstone query text"); 149 return null; 150 } 90 151 91 152 createResults(); 92 153 93 154 _results.save(); 94 155 95 156 String resultFrameName = _results.getName(); 96 if (_clicked != null) 157 if (_clicked != null) { 97 158 _clicked.setLink(resultFrameName); 159 _clicked.setText(resultsTitle); 160 } 98 161 99 162 return _results.getFirstFrame(); … … 104 167 } 105 168 169 /** 170 * TODO make this more efficient so the maps are loaded on demand... 171 * 172 * @param queryText 173 */ 106 174 protected void doQuery(String queryText) { 175 _pageCountMap.clear(); 176 _dateMap.clear(); 177 _titleMap.clear(); 178 107 179 Query query = createQuery(queryText); 108 180 QueryOutcome queryOutcome = _gsdl.issueQueryToServer(query); … … 113 185 114 186 Query query = new Query(); 115 116 187 // set the query options 117 188 query.setQueryText(queryText); 118 119 189 query.setIndex(_indexKeys[_indexChoice]); 120 query.setMaxDocsToReturn(_ maxResults);190 query.setMaxDocsToReturn(_thisMaxResults); 121 191 122 192 if (_doStemming) { … … 138 208 139 209 Vector<Result> results = queryOutcome.getResults(); 140 for (Enumeration<Result> e = results.elements(); e.hasMoreElements();) { 141 Result result = e.nextElement(); 210 for (Result result : results) { 142 211 getResultMetadata(result); 143 212 } … … 193 262 ResultDocument rd = _gsdl.getDocument(docID); 194 263 int docRank = result.getRank(); 195 // Put the details on a separate frame 196 FrameCreator details = new FrameCreator(rd.getTitle()); 197 details.addText(getDetails(rd), null, null, null, true); 198 199 resultsCreator.addText((docRank + 1) + ". " + rd.getTitle(), null, 200 details.getName(), "getTextFromChildFrame", false); 201 202 FrameGraphics.requestRefresh(true); 264 265 addText(rd, resultsCreator, (docRank + 1) + ". " + rd.getTitle()); 203 266 } 204 267 } … … 252 315 } 253 316 317 @Override 318 public Frame getResultFrame() { 319 if (_useLastSearchResults && _currentResultSet == null) 320 return null; 321 322 return super.getResultFrame(); 323 } 324 325 protected void addText(ResultDocument rd, FrameCreator results, String text) { 326 // Put the details on a separate frame 327 FrameCreator details = new FrameCreator(rd.getTitle()); 328 details.addText(getDetails(rd), null, null, null, true); 329 330 if (_showDate && rd.metadataExists("Date")) 331 text += ", " + rd.getDate(); 332 333 if (_showAbstract && rd.metadataExists("Abstract")) 334 text += "\n " + rd.getAbstract(); 335 336 if (_showAuthors && rd.metadataExists("Creator")) 337 text += "\nAuthors" + rd.getAuthors().toString(); 338 339 if (_showKeywords && rd.getKeywords().size() > 0) 340 text += "\nKeywords" + rd.getKeywords().toString(); 341 342 results.addText(text, null, details.getName(), "getTextFromChildFrame", 343 false); 344 345 FrameGraphics.requestRefresh(true); 346 } 347 254 348 }
Note:
See TracChangeset
for help on using the changeset viewer.