source: trunk/src/org/expeditee/agents/SearchGreenstoneByDate.java@ 1510

Last change on this file since 1510 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 3.0 KB
Line 
1/**
2 * SearchGreenstoneByDate.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.agents;
20
21import java.util.Collections;
22import java.util.Map;
23import java.util.Vector;
24
25import org.expeditee.greenstone.Result;
26import org.expeditee.greenstone.ResultDocument;
27import org.expeditee.gui.FrameCreator;
28
29public class SearchGreenstoneByDate extends SearchGreenstone {
30
31 public SearchGreenstoneByDate(int resultsCount, String searchText) {
32 super(resultsCount, searchText);
33 }
34
35 public SearchGreenstoneByDate(String searchText) {
36 super(searchText);
37 }
38
39 public SearchGreenstoneByDate() {
40 super();
41 }
42
43 protected void createResults() {
44 if(_dateMap.isEmpty()){
45 initialiseDateMap(_currentResultSet);
46 }
47 viewByDate(_dateMap, _results);
48 }
49
50 public void initialiseDateMap(Vector<Result> results) {
51 for (Result result : results) {
52 String docID = result.getDocID();
53
54 ResultDocument rd = _gsdl.getDocument(docID);
55
56 if (rd.metadataExists("Date")) {
57 addToDateMap(docID, rd);
58 }
59 }
60 }
61
62 public void addToDateMap(String docID, ResultDocument rd) {
63 if (_dateMap.containsKey(rd.getDate())) {
64 Vector<String> dateVector = _dateMap.get(rd.getDate());
65 if (!dateVector.contains(docID)) {
66 dateVector.addElement(docID);
67 }
68 _dateMap.put(rd.getDate(), dateVector);
69 } else {
70 Vector<String> dateVector = new Vector<String>();
71 dateVector.addElement(docID);
72 _dateMap.put(rd.getDate(), dateVector);
73 }
74 }
75
76 /**
77 * This method provides an alternative view of the result set It uses the
78 * dateMap which organises results according to the year in which they were
79 * published
80 *
81 * You will need to write a similar method for any additional view that you
82 * implement
83 *
84 * You may wish to modify this method to provide a better layout of the
85 * output
86 */
87 private void viewByDate(Map<String, Vector<String>> dateMap,
88 FrameCreator results) {
89 Vector<String> theDates = new Vector<String>(dateMap.keySet());
90 Collections.sort(theDates);
91
92 for (String date : theDates) {
93 Vector<String> ids = dateMap.get(date);
94
95 // Text dateText = results.addText(date, null, null, null, false);
96 // dateText.setFontStyle("bold");
97
98 for (String docID : ids) {
99 ResultDocument rd = _gsdl.getDocument(docID);
100 addText(rd, results, date + "- " + rd.getTitle());
101 }
102 }
103 }
104}
Note: See TracBrowser for help on using the repository browser.