1 | package org.expeditee.agents;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collections;
|
---|
5 | import java.util.Comparator;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Map;
|
---|
8 |
|
---|
9 | import org.expeditee.greenstone.ResultDocument;
|
---|
10 | import org.expeditee.gui.FrameCreator;
|
---|
11 | import org.expeditee.stats.Formatter;
|
---|
12 |
|
---|
13 | public class DisplayGreenstoneSession extends SearchGreenstone {
|
---|
14 |
|
---|
15 | public DisplayGreenstoneSession(int resultsCount) {
|
---|
16 | super(resultsCount);
|
---|
17 | }
|
---|
18 |
|
---|
19 | public DisplayGreenstoneSession() {
|
---|
20 | super();
|
---|
21 | }
|
---|
22 |
|
---|
23 | protected void createResults() {
|
---|
24 | if (!_gsdl.getSessionResults().isEmpty()) {
|
---|
25 | viewSessionResults(_gsdl.getSessionResults(), _results);
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | protected String getResultsTitle() {
|
---|
30 | return "SessionResults at " + Formatter.getDateTime();
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * This method provides an alternative view of the result set It uses the
|
---|
35 | * dateMap which organises results according to the year in which they were
|
---|
36 | * published
|
---|
37 | *
|
---|
38 | * You will need to write a similar method for any additional view that you
|
---|
39 | * implement
|
---|
40 | *
|
---|
41 | * You may wish to modify this method to provide a better layout of the
|
---|
42 | * output
|
---|
43 | */
|
---|
44 | private void viewSessionResults(Map<String, ResultDocument> sessionResults,
|
---|
45 | FrameCreator results) {
|
---|
46 |
|
---|
47 | List<ResultDocument> resultDocArrayList = new ArrayList<ResultDocument>(
|
---|
48 | sessionResults.values());
|
---|
49 | Collections.sort(resultDocArrayList,
|
---|
50 | new DescendingSessionScoreComparator());
|
---|
51 |
|
---|
52 | int docRank = 1;
|
---|
53 |
|
---|
54 | for(ResultDocument rd: resultDocArrayList){
|
---|
55 | addText(rd, results, docRank++ + ". " + rd.getTitle());
|
---|
56 | }
|
---|
57 |
|
---|
58 | }
|
---|
59 |
|
---|
60 | protected String getCursorText() {
|
---|
61 | return getResultsTitle();
|
---|
62 | }
|
---|
63 |
|
---|
64 | static class DescendingSessionScoreComparator implements Comparator<ResultDocument> {
|
---|
65 |
|
---|
66 | public int compare(ResultDocument d1, ResultDocument d2) {
|
---|
67 |
|
---|
68 | double sessionScore1 = d1.getSessionScore();
|
---|
69 | double sessionScore2 = d2.getSessionScore();
|
---|
70 |
|
---|
71 | if (sessionScore1 > sessionScore2) {
|
---|
72 | return -1;
|
---|
73 | } else if (sessionScore1 < sessionScore2) {
|
---|
74 | return 1;
|
---|
75 | } else {
|
---|
76 | return 0;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected String getNoResultsMessage() {
|
---|
82 | return "The session results set is empty";
|
---|
83 | }
|
---|
84 | }
|
---|