source: trunk/src/org/expeditee/agents/SearchGreenstoneByPages.java@ 1430

Last change on this file since 1430 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.3 KB
Line 
1/**
2 * SearchGreenstoneByPages.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 SearchGreenstoneByPages extends SearchGreenstone {
30
31 public SearchGreenstoneByPages(int resultsCount, String searchText) {
32 super(resultsCount, searchText);
33 }
34
35 public SearchGreenstoneByPages(String searchText) {
36 super(searchText);
37 }
38
39 public SearchGreenstoneByPages() {
40 super();
41 }
42
43 protected void createResults() {
44 if (_pageCountMap.isEmpty()) {
45 initialisePageCountMap(_currentResultSet);
46 }
47 viewByPageCount(_pageCountMap, _results);
48 }
49
50 public void initialisePageCountMap(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("Pages")) {
57 addToPageCountMap(docID, rd);
58 }
59 }
60 }
61
62 public void addToPageCountMap(String docID, ResultDocument rd) {
63 int pages = 1;
64 String[] pageRange = rd.getPages().trim().split("-");
65
66 if (pageRange.length == 2) {
67 try {
68 pages = Integer.parseInt(pageRange[1])
69 - Integer.parseInt(pageRange[0]) + 1;
70 } catch (Exception e) {
71 return;
72 }
73 }
74
75 if (_pageCountMap.containsKey(pages)) {
76 Vector<String> dateVector = _pageCountMap.get(pages);
77 if (!dateVector.contains(docID)) {
78 dateVector.addElement(docID);
79 }
80 } else {
81 Vector<String> dateVector = new Vector<String>();
82 dateVector.addElement(docID);
83 _pageCountMap.put(pages, dateVector);
84 }
85 }
86
87 /**
88 * This method provides an alternative view of the result set It uses the
89 * dateMap which organises results according to the year in which they were
90 * published
91 *
92 * You will need to write a similar method for any additional view that you
93 * implement
94 *
95 * You may wish to modify this method to provide a better layout of the
96 * output
97 */
98 private void viewByPageCount(Map<Integer, Vector<String>> pageCountMap,
99 FrameCreator results) {
100 Vector<Integer> thePageCounts = new Vector<Integer>(pageCountMap
101 .keySet());
102 Collections.sort(thePageCounts);
103
104 for (Integer pageCount : thePageCounts) {
105 Vector<String> ids = pageCountMap.get(pageCount);
106
107 // Text dateText = results.addText(date, null, null, null, false);
108 // dateText.setFontStyle("bold");
109
110 for (String docID : ids) {
111 ResultDocument rd = _gsdl.getDocument(docID);
112 addText(rd, results, pageCount + "- " + rd.getTitle());
113 }
114 }
115 }
116}
Note: See TracBrowser for help on using the repository browser.