1 | package org.expeditee.agents;
|
---|
2 |
|
---|
3 | import java.util.Collections;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.Vector;
|
---|
6 |
|
---|
7 | import org.expeditee.greenstone.Result;
|
---|
8 | import org.expeditee.greenstone.ResultDocument;
|
---|
9 | import org.expeditee.gui.FrameCreator;
|
---|
10 | import org.expeditee.gui.FrameGraphics;
|
---|
11 |
|
---|
12 | public class SearchGreenstoneByDate extends SearchGreenstone {
|
---|
13 |
|
---|
14 | public SearchGreenstoneByDate(String searchText) {
|
---|
15 | super(searchText);
|
---|
16 | }
|
---|
17 |
|
---|
18 | public SearchGreenstoneByDate(int resultsCount, String searchText) {
|
---|
19 | super(resultsCount, searchText);
|
---|
20 | }
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * dateMap is a hash table. The keys are year values. the data associated
|
---|
24 | * with each key is a Vector of document IDs therefore, for the current
|
---|
25 | * result set you can get the set of years in which the results were
|
---|
26 | * published, and for each year you can get the set of documents published
|
---|
27 | * in that year
|
---|
28 | *
|
---|
29 | * If you want to introduce additional mappings (eg document written by
|
---|
30 | * authors) you should introduce additional structures here (HashMap used in
|
---|
31 | * the same way as dateMap will probably suffice
|
---|
32 | *
|
---|
33 | */
|
---|
34 | private static HashMap<String, Vector<String>> _dateMap = new HashMap<String, Vector<String>>();
|
---|
35 |
|
---|
36 | protected void doQuery(String queryText) {
|
---|
37 | _dateMap.clear();
|
---|
38 |
|
---|
39 | super.doQuery(queryText);
|
---|
40 |
|
---|
41 | initialiseDateMap(_currentResultSet);
|
---|
42 | }
|
---|
43 |
|
---|
44 | protected void createResults() {
|
---|
45 | viewByDate(_dateMap, _results);
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void initialiseDateMap(Vector<Result> results) {
|
---|
49 | for (Result result : results) {
|
---|
50 | String docID = result.getDocID();
|
---|
51 |
|
---|
52 | ResultDocument rd = _gsdl.getDocument(docID);
|
---|
53 |
|
---|
54 | if (rd.metadataExists("Date")) {
|
---|
55 | addToDateMap(docID, rd);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | public void addToDateMap(String docID, ResultDocument rd) {
|
---|
61 | if (_dateMap.containsKey(rd.getDate())) {
|
---|
62 | Vector<String> dateVector = _dateMap.get(rd.getDate());
|
---|
63 | if (!dateVector.contains(docID)) {
|
---|
64 | dateVector.addElement(docID);
|
---|
65 | }
|
---|
66 | _dateMap.put(rd.getDate(), dateVector);
|
---|
67 | } else {
|
---|
68 | Vector<String> dateVector = new Vector<String>();
|
---|
69 | dateVector.addElement(docID);
|
---|
70 | _dateMap.put(rd.getDate(), dateVector);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * This method provides an alternative view of the result set It uses the
|
---|
76 | * dateMap which organises results according to the year in which they were
|
---|
77 | * published
|
---|
78 | *
|
---|
79 | * You will need to write a similar method for any additional view that you
|
---|
80 | * implement
|
---|
81 | *
|
---|
82 | * You may wish to modify this method to provide a better layout of the
|
---|
83 | * output
|
---|
84 | */
|
---|
85 | private void viewByDate(HashMap<String, Vector<String>> dateMap,
|
---|
86 | FrameCreator results) {
|
---|
87 | Vector<String> theDates = new Vector<String>(dateMap.keySet());
|
---|
88 | Collections.sort(theDates);
|
---|
89 |
|
---|
90 | for (String date : theDates) {
|
---|
91 | Vector<String> ids = dateMap.get(date);
|
---|
92 |
|
---|
93 | // Text dateText = results.addText(date, null, null, null, false);
|
---|
94 | // dateText.setFontStyle("bold");
|
---|
95 |
|
---|
96 | for (String docID : ids) {
|
---|
97 | ResultDocument rd = _gsdl.getDocument(docID);
|
---|
98 |
|
---|
99 | // Put the details on a separate frame
|
---|
100 | FrameCreator details = new FrameCreator(rd.getTitle());
|
---|
101 | details.addText(getDetails(rd), null, null, null, true);
|
---|
102 |
|
---|
103 | results.addText(date + "- " + rd.getTitle(), null, details
|
---|
104 | .getName(), "getTextFromChildFrame", false);
|
---|
105 |
|
---|
106 | FrameGraphics.requestRefresh(true);
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|