Ignore:
Timestamp:
09/23/08 15:05:41 (16 years ago)
Author:
ra33
Message:

Added more features to the Greenstone Search

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/agents/SearchGreenstone.java

    r312 r313  
    11package org.expeditee.agents;
    22
    3 import java.util.Collections;
    43import java.util.Enumeration;
    54import java.util.HashMap;
     5import java.util.Map;
    66import java.util.Vector;
    77
     
    1212import org.expeditee.greenstone.ResultDocument;
    1313import org.expeditee.gui.AttributeValuePair;
     14import org.expeditee.gui.DisplayIO;
    1415import org.expeditee.gui.Frame;
    1516import org.expeditee.gui.FrameCreator;
    1617import org.expeditee.gui.FrameGraphics;
     18import org.expeditee.gui.FrameMouseActions;
     19import org.expeditee.gui.MessageBay;
    1720import org.expeditee.items.Text;
    1821
    1922public class SearchGreenstone extends SearchAgent {
    2023
     24        private static String _fullCaseSearchQuery = null;
     25
    2126        private static boolean _doCasefolding = true;
    2227
     
    2732        private static String _maxResults = "10";
    2833
     34        private static boolean _showAbstract = false;
     35        private static boolean _showKeywords = false;
     36        private static boolean _showAuthors = false;
     37        private static boolean _showDate = false;
     38
     39        private String _thisMaxResults = "10";
     40
    2941        private int _indexChoice = 1;
    3042
     
    3547        private static String[] _indexKeys = { "TX", "TI", "JO", "BO", "CR", "KE" };
    3648
    37         protected static Vector<Result> _currentResultSet;
     49        protected static Vector<Result> _currentResultSet = null;
     50
     51        private boolean _useLastSearchResults = false;
     52
     53        /**
     54         * dateMap is a hash table. The keys are year values. the data associated
     55         * with each key is a Vector of document IDs therefore, for the current
     56         * result set you can get the set of years in which the results were
     57         * published, and for each year you can get the set of documents published
     58         * in that year
     59         *
     60         * If you want to introduce additional mappings (eg document written by
     61         * authors) you should introduce additional structures here (HashMap used in
     62         * the same way as dateMap will probably suffice
     63         *
     64         */
     65        protected static Map<String, Vector<String>> _dateMap = new HashMap<String, Vector<String>>();
     66
     67        protected static Map<Integer, Vector<String>> _pageCountMap = new HashMap<Integer, Vector<String>>();
     68
     69        protected static Map<String, String> _titleMap = new HashMap<String, String>();
     70
     71        public SearchGreenstone(int resultsCount, String searchText) {
     72                super(searchText);
     73                _thisMaxResults = resultsCount + "";
     74                _fullCaseSearchQuery = searchText;
     75        }
    3876
    3977        public SearchGreenstone(String searchText) {
    4078                super(searchText);
    41         }
    42 
    43         public SearchGreenstone(int resultsCount, String searchText) {
    44                 this(searchText);
    45                 _maxResults = resultsCount + "";
     79                _thisMaxResults = _maxResults;
     80                _fullCaseSearchQuery = searchText;
     81        }
     82
     83        public SearchGreenstone() {
     84                super(null);
     85                _useLastSearchResults = true;
    4686        }
    4787
     
    61101                        if (attribute.equals("campus"))
    62102                                _locationChoice = 0;
    63                         if (attribute.equals("autoconnect"))
     103                        else if (attribute.equals("autoconnect"))
    64104                                connect();
    65105
    66                         if (attribute.equals("maxresults")) {
     106                        else if (attribute.equals("maxresults")) {
    67107                                try {
    68108                                        _maxResults = avp.getValue();
     
    71111                        }
    72112
    73                         if (attribute.equals("dostemming"))
     113                        else if (attribute.equals("dostemming"))
    74114                                _doStemming = true;
     115                        else if (attribute.startsWith("showabstract"))
     116                                _showAbstract = true;
     117                        else if (attribute.startsWith("showauthor"))
     118                                _showAuthors = true;
     119                        else if (attribute.startsWith("showkeyword"))
     120                                _showKeywords = true;
     121                        else if (attribute.startsWith("showdate"))
     122                                _showDate = true;
    75123                }
    76124        }
     
    83131        @Override
    84132        protected Frame process(Frame frame) {
    85                 _results.setTitle("SearchGreenstone [" + _pattern + "]");
    86 
    87                 connect();
    88 
    89                 doQuery(_pattern);
     133                String resultsTitle = this.getClass().getSimpleName() + "["
     134                                + _fullCaseSearchQuery + "]";
     135                _results.setTitle(resultsTitle);
     136
     137                if (!_useLastSearchResults) {
     138                        connect();
     139                        doQuery(_pattern);
     140                } else if (_currentResultSet != null) {
     141                        Text newText = DisplayIO.getCurrentFrame().createNewText(
     142                                        _fullCaseSearchQuery);
     143                        _clicked = newText;
     144                        FrameMouseActions.pickup(newText);
     145                }
     146
     147                if (_currentResultSet == null) {
     148                        MessageBay.errorMessage("Could not find Greenstone query text");
     149                        return null;
     150                }
    90151
    91152                createResults();
    92                
     153
    93154                _results.save();
    94155
    95156                String resultFrameName = _results.getName();
    96                 if (_clicked != null)
     157                if (_clicked != null) {
    97158                        _clicked.setLink(resultFrameName);
     159                        _clicked.setText(resultsTitle);
     160                }
    98161
    99162                return _results.getFirstFrame();
     
    104167        }
    105168
     169        /**
     170         * TODO make this more efficient so the maps are loaded on demand...
     171         *
     172         * @param queryText
     173         */
    106174        protected void doQuery(String queryText) {
     175                _pageCountMap.clear();
     176                _dateMap.clear();
     177                _titleMap.clear();
     178
    107179                Query query = createQuery(queryText);
    108180                QueryOutcome queryOutcome = _gsdl.issueQueryToServer(query);
     
    113185
    114186                Query query = new Query();
    115 
    116187                // set the query options
    117188                query.setQueryText(queryText);
    118 
    119189                query.setIndex(_indexKeys[_indexChoice]);
    120                 query.setMaxDocsToReturn(_maxResults);
     190                query.setMaxDocsToReturn(_thisMaxResults);
    121191
    122192                if (_doStemming) {
     
    138208
    139209                Vector<Result> results = queryOutcome.getResults();
    140                 for (Enumeration<Result> e = results.elements(); e.hasMoreElements();) {
    141                         Result result = e.nextElement();
     210                for (Result result : results) {
    142211                        getResultMetadata(result);
    143212                }
     
    193262                        ResultDocument rd = _gsdl.getDocument(docID);
    194263                        int docRank = result.getRank();
    195                         // Put the details on a separate frame
    196                         FrameCreator details = new FrameCreator(rd.getTitle());
    197                         details.addText(getDetails(rd), null, null, null, true);
    198 
    199                         resultsCreator.addText((docRank + 1) + ". " + rd.getTitle(), null,
    200                                         details.getName(), "getTextFromChildFrame", false);
    201 
    202                         FrameGraphics.requestRefresh(true);
     264
     265                        addText(rd, resultsCreator, (docRank + 1) + ". " + rd.getTitle());
    203266                }
    204267        }
     
    252315        }
    253316
     317        @Override
     318        public Frame getResultFrame() {
     319                if (_useLastSearchResults && _currentResultSet == null)
     320                        return null;
     321
     322                return super.getResultFrame();
     323        }
     324
     325        protected void addText(ResultDocument rd, FrameCreator results, String text) {
     326                // Put the details on a separate frame
     327                FrameCreator details = new FrameCreator(rd.getTitle());
     328                details.addText(getDetails(rd), null, null, null, true);
     329
     330                if (_showDate && rd.metadataExists("Date"))
     331                        text += ", " + rd.getDate();
     332               
     333                if (_showAbstract && rd.metadataExists("Abstract"))
     334                        text += "\n  " + rd.getAbstract();
     335               
     336                if (_showAuthors && rd.metadataExists("Creator"))
     337                        text += "\nAuthors" + rd.getAuthors().toString();
     338               
     339                if (_showKeywords && rd.getKeywords().size() > 0)
     340                        text += "\nKeywords" + rd.getKeywords().toString();
     341
     342                results.addText(text, null, details.getName(), "getTextFromChildFrame",
     343                                false);
     344
     345                FrameGraphics.requestRefresh(true);
     346        }
     347
    254348}
Note: See TracChangeset for help on using the changeset viewer.