1 | package org.expeditee.agents;
|
---|
2 |
|
---|
3 | import java.util.Collections;
|
---|
4 | import java.util.Map;
|
---|
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 |
|
---|
11 | public class SearchGreenstoneByDate extends SearchGreenstone {
|
---|
12 |
|
---|
13 | public SearchGreenstoneByDate(int resultsCount, String searchText) {
|
---|
14 | super(resultsCount, searchText);
|
---|
15 | }
|
---|
16 |
|
---|
17 | public SearchGreenstoneByDate(String searchText) {
|
---|
18 | super(searchText);
|
---|
19 | }
|
---|
20 |
|
---|
21 | public SearchGreenstoneByDate() {
|
---|
22 | super();
|
---|
23 | }
|
---|
24 |
|
---|
25 | protected void createResults() {
|
---|
26 | if(_dateMap.isEmpty()){
|
---|
27 | initialiseDateMap(_currentResultSet);
|
---|
28 | }
|
---|
29 | viewByDate(_dateMap, _results);
|
---|
30 | }
|
---|
31 |
|
---|
32 | public void initialiseDateMap(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("Date")) {
|
---|
39 | addToDateMap(docID, rd);
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public void addToDateMap(String docID, ResultDocument rd) {
|
---|
45 | if (_dateMap.containsKey(rd.getDate())) {
|
---|
46 | Vector<String> dateVector = _dateMap.get(rd.getDate());
|
---|
47 | if (!dateVector.contains(docID)) {
|
---|
48 | dateVector.addElement(docID);
|
---|
49 | }
|
---|
50 | _dateMap.put(rd.getDate(), dateVector);
|
---|
51 | } else {
|
---|
52 | Vector<String> dateVector = new Vector<String>();
|
---|
53 | dateVector.addElement(docID);
|
---|
54 | _dateMap.put(rd.getDate(), dateVector);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * This method provides an alternative view of the result set It uses the
|
---|
60 | * dateMap which organises results according to the year in which they were
|
---|
61 | * published
|
---|
62 | *
|
---|
63 | * You will need to write a similar method for any additional view that you
|
---|
64 | * implement
|
---|
65 | *
|
---|
66 | * You may wish to modify this method to provide a better layout of the
|
---|
67 | * output
|
---|
68 | */
|
---|
69 | private void viewByDate(Map<String, Vector<String>> dateMap,
|
---|
70 | FrameCreator results) {
|
---|
71 | Vector<String> theDates = new Vector<String>(dateMap.keySet());
|
---|
72 | Collections.sort(theDates);
|
---|
73 |
|
---|
74 | for (String date : theDates) {
|
---|
75 | Vector<String> ids = dateMap.get(date);
|
---|
76 |
|
---|
77 | // Text dateText = results.addText(date, null, null, null, false);
|
---|
78 | // dateText.setFontStyle("bold");
|
---|
79 |
|
---|
80 | for (String docID : ids) {
|
---|
81 | ResultDocument rd = _gsdl.getDocument(docID);
|
---|
82 | addText(rd, results, date + "- " + rd.getTitle());
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|