source: trunk/src/org/expeditee/agents/SearchGreenstoneByTitle.java@ 636

Last change on this file since 636 was 328, checked in by ra33, 16 years ago
File size: 1.6 KB
Line 
1package org.expeditee.agents;
2
3import java.util.Collections;
4import java.util.Map;
5import java.util.Vector;
6
7import org.expeditee.greenstone.Result;
8import org.expeditee.greenstone.ResultDocument;
9import org.expeditee.gui.FrameCreator;
10
11public class SearchGreenstoneByTitle extends SearchGreenstone {
12
13 public SearchGreenstoneByTitle(int resultsCount, String searchText) {
14 super(resultsCount, searchText);
15 }
16
17 public SearchGreenstoneByTitle(String searchText) {
18 super(searchText);
19 }
20
21 public SearchGreenstoneByTitle() {
22 super();
23 }
24
25 protected void createResults() {
26 if (_titleMap.isEmpty()) {
27 initialiseTitleMap(_currentResultSet);
28 }
29 viewByTitle(_titleMap, _results);
30 }
31
32 public void initialiseTitleMap(Vector<Result> results) {
33 for (Result result : results) {
34 String docID = result.getDocID();
35
36 ResultDocument rd = _gsdl.getDocument(docID);
37
38 if (rd.metadataExists("Title")) {
39 _titleMap.put(rd.getTitle(), docID);
40 }
41 }
42 }
43
44 /**
45 * This method provides an alternative view of the result set It uses the
46 * dateMap which organises results according to the year in which they were
47 * published
48 *
49 * You will need to write a similar method for any additional view that you
50 * implement
51 *
52 * You may wish to modify this method to provide a better layout of the
53 * output
54 */
55 private void viewByTitle(Map<String, String> titleMap,
56 FrameCreator results) {
57 Vector<String> theTitles = new Vector<String>(titleMap.keySet());
58 Collections.sort(theTitles);
59
60 for (String title : theTitles) {
61 String id = titleMap.get(title);
62
63 ResultDocument rd = _gsdl.getDocument(id);
64
65 addText(rd, results, rd.getTitle());
66 }
67 }
68}
Note: See TracBrowser for help on using the repository browser.