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 SearchGreenstoneByPages extends SearchGreenstone {
|
---|
12 |
|
---|
13 | public SearchGreenstoneByPages(int resultsCount, String searchText) {
|
---|
14 | super(resultsCount, searchText);
|
---|
15 | }
|
---|
16 |
|
---|
17 | public SearchGreenstoneByPages(String searchText) {
|
---|
18 | super(searchText);
|
---|
19 | }
|
---|
20 |
|
---|
21 | public SearchGreenstoneByPages() {
|
---|
22 | super();
|
---|
23 | }
|
---|
24 |
|
---|
25 | protected void createResults() {
|
---|
26 | if (_pageCountMap.isEmpty()) {
|
---|
27 | initialisePageCountMap(_currentResultSet);
|
---|
28 | }
|
---|
29 | viewByPageCount(_pageCountMap, _results);
|
---|
30 | }
|
---|
31 |
|
---|
32 | public void initialisePageCountMap(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("Pages")) {
|
---|
39 | addToPageCountMap(docID, rd);
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public void addToPageCountMap(String docID, ResultDocument rd) {
|
---|
45 | int pages = 1;
|
---|
46 | String[] pageRange = rd.getPages().trim().split("-");
|
---|
47 |
|
---|
48 | if (pageRange.length == 2) {
|
---|
49 | try {
|
---|
50 | pages = Integer.parseInt(pageRange[1])
|
---|
51 | - Integer.parseInt(pageRange[0]) + 1;
|
---|
52 | } catch (Exception e) {
|
---|
53 | return;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | if (_pageCountMap.containsKey(pages)) {
|
---|
58 | Vector<String> dateVector = _pageCountMap.get(pages);
|
---|
59 | if (!dateVector.contains(docID)) {
|
---|
60 | dateVector.addElement(docID);
|
---|
61 | }
|
---|
62 | } else {
|
---|
63 | Vector<String> dateVector = new Vector<String>();
|
---|
64 | dateVector.addElement(docID);
|
---|
65 | _pageCountMap.put(pages, dateVector);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * This method provides an alternative view of the result set It uses the
|
---|
71 | * dateMap which organises results according to the year in which they were
|
---|
72 | * published
|
---|
73 | *
|
---|
74 | * You will need to write a similar method for any additional view that you
|
---|
75 | * implement
|
---|
76 | *
|
---|
77 | * You may wish to modify this method to provide a better layout of the
|
---|
78 | * output
|
---|
79 | */
|
---|
80 | private void viewByPageCount(Map<Integer, Vector<String>> pageCountMap,
|
---|
81 | FrameCreator results) {
|
---|
82 | Vector<Integer> thePageCounts = new Vector<Integer>(pageCountMap
|
---|
83 | .keySet());
|
---|
84 | Collections.sort(thePageCounts);
|
---|
85 |
|
---|
86 | for (Integer pageCount : thePageCounts) {
|
---|
87 | Vector<String> ids = pageCountMap.get(pageCount);
|
---|
88 |
|
---|
89 | // Text dateText = results.addText(date, null, null, null, false);
|
---|
90 | // dateText.setFontStyle("bold");
|
---|
91 |
|
---|
92 | for (String docID : ids) {
|
---|
93 | ResultDocument rd = _gsdl.getDocument(docID);
|
---|
94 | addText(rd, results, pageCount + "- " + rd.getTitle());
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|