Changeset 313


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

Added more features to the Greenstone Search

Location:
trunk/src/org/expeditee
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Actions.java

    r311 r313  
    77import java.lang.reflect.Modifier;
    88import java.net.URL;
     9import java.rmi.UnexpectedException;
    910import java.util.ArrayList;
    1011import java.util.Collection;
     
    506507                                        params = new Object[paramCount];
    507508                                        String[] paramStrings = parameters.split("\\s+");
    508                                         if (paramCount != paramStrings.length)
     509                                        /**
     510                                         * Any extra parametres will be treated as the rest of the
     511                                         * string if the last param is a string
     512                                         */
     513                                        if (paramCount > paramStrings.length)
    509514                                                continue;
    510                                         for (int i = 0; i < paramCount; i++) {
    511                                                 SString nextParam = new SString(paramStrings[i]);
    512                                                 try {
     515                                        /**
     516                                         * If there are extra parametres the last param must be a
     517                                         * String
     518                                         */
     519                                        int lastParam = paramTypes.length - 1;
     520
     521                                        if (paramCount < paramStrings.length
     522                                                        && !paramTypes[lastParam].equals(String.class))
     523                                                continue;
     524                                        try {
     525                                                for (int i = 0; i < paramCount; i++) {
     526                                                        SString nextParam = new SString(paramStrings[i]);
    513527                                                        params[i] = null;
    514528                                                        if (paramTypes[i].equals(int.class)
     
    531545                                                                params[i] = nextParam.stringValue();
    532546                                                        } else {
    533                                                                 continue;
     547                                                                throw new UnexpectedException(
     548                                                                                "Unexpected type "
     549                                                                                                + paramTypes[i].getClass()
     550                                                                                                                .toString());
    534551                                                        }
    535                                                 } catch (Exception e) {
    536                                                         continue;
    537552                                                }
     553                                        } catch (Exception e) {
     554                                                continue;
    538555                                        }
     556                                        /** Append extra params on the end of the last string param */
     557                                        String s = params[lastParam].toString();
     558                                        for (int i = paramCount; i < paramStrings.length; i++) {
     559                                                s += ' ' + paramStrings[i];
     560                                        }
     561                                        params[lastParam] = s;
     562
    539563                                        con = c;
    540564                                        break;
     
    861885                try {
    862886                        return PerformAction(current, launcher, command);
    863                 }catch (RuntimeException e) {
     887                } catch (RuntimeException e) {
    864888                        MessageBay.errorMessage("Action failed: " + e.getMessage());
    865889                } catch (Exception e) {
    866                         MessageBay.errorMessage("Action failed: " + e.getClass().getSimpleName());
     890                        MessageBay.errorMessage("Action failed: "
     891                                        + e.getClass().getSimpleName());
    867892                }
    868893                return null;
  • trunk/src/org/expeditee/actions/Simple.java

    r311 r313  
    933933                                // The fast search does not do replacement
    934934                                if (bReplace) {
    935                                         searchAgent = new SearchFrameset(null, firstFrame, maxFrame);
     935                                        searchAgent = new SearchFrameset(firstFrame, maxFrame, null);
    936936                                } else {
    937                                         searchAgent = new SearchFramesetFast(null, firstFrame, maxFrame);
     937                                        searchAgent = new SearchFramesetFast(firstFrame, maxFrame, null);
    938938                                }
    939939                                searchAgent.initialise(null, null, frameset, resultsFrameset,
  • trunk/src/org/expeditee/agents/DefaultAgent.java

    r179 r313  
    107107
    108108        public boolean hasResultFrame() {
    109                 return _end != null;
     109                return getResultFrame() != null;
    110110        }
    111111       
  • trunk/src/org/expeditee/agents/SearchFrameset.java

    r292 r313  
    88        private long _maxFrame = Integer.MAX_VALUE;
    99       
    10         public SearchFrameset(String searchText) {
    11                 super(searchText);
    12         }
    13        
    14         public SearchFrameset(String searchText, long firstFrame, long maxFrame) {
     10        public SearchFrameset(long firstFrame, long maxFrame, String searchText) {
    1511                this(searchText);
    1612                _firstFrame = firstFrame;
    1713                _maxFrame = maxFrame;
     14        }
     15       
     16        public SearchFrameset(String searchText) {
     17                super(searchText);
    1818        }
    1919
  • trunk/src/org/expeditee/agents/SearchFramesetFast.java

    r298 r313  
    1212        private long _maxFrame = Integer.MAX_VALUE;
    1313
    14         public SearchFramesetFast(String searchText) {
    15                 super(searchText);
    16         }
    17        
    18         public SearchFramesetFast(String searchText, long firstFrame, long maxFrame) {
     14        public SearchFramesetFast(long firstFrame, long maxFrame, String searchText) {
    1915                this(searchText);
    2016                _firstFrame = firstFrame;
    2117                _maxFrame = maxFrame;
     18        }
     19       
     20        public SearchFramesetFast(String searchText) {
     21                super(searchText);
    2222        }
    2323
  • trunk/src/org/expeditee/agents/SearchFramesetNoResults.java

    r298 r313  
    1313        private Map<String, Collection<String>> _results = new HashMap<String, Collection<String>>();
    1414       
    15         public SearchFramesetNoResults(String searchText) {
    16                 super(searchText);
    17         }
    18        
    19         public SearchFramesetNoResults(String searchText, long firstFrame, long maxFrame) {
     15        public SearchFramesetNoResults(long firstFrame, long maxFrame, String searchText) {
    2016                this(searchText);
    2117                _firstFrame = firstFrame;
    2218                _maxFrame = maxFrame;
     19        }
     20       
     21        public SearchFramesetNoResults(String searchText) {
     22                super(searchText);
    2323        }
    2424
  • 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}
  • trunk/src/org/expeditee/agents/SearchGreenstoneByDate.java

    r312 r313  
    22
    33import java.util.Collections;
    4 import java.util.HashMap;
     4import java.util.Map;
    55import java.util.Vector;
    66
     
    1212public class SearchGreenstoneByDate extends SearchGreenstone {
    1313
     14        public SearchGreenstoneByDate(int resultsCount, String searchText) {
     15                super(resultsCount, searchText);
     16        }
     17       
    1418        public SearchGreenstoneByDate(String searchText) {
    1519                super(searchText);
    1620        }
    17 
    18         public SearchGreenstoneByDate(int resultsCount, String searchText) {
    19                 super(resultsCount, searchText);
    20         }
    21 
    22         /**
    23          * dateMap is a hash table. The keys are year values. the data associated
    24          * with each key is a Vector of document IDs therefore, for the current
    25          * result set you can get the set of years in which the results were
    26          * published, and for each year you can get the set of documents published
    27          * in that year
    28          *
    29          * If you want to introduce additional mappings (eg document written by
    30          * authors) you should introduce additional structures here (HashMap used in
    31          * the same way as dateMap will probably suffice
    32          *
    33          */
    34         private static HashMap<String, Vector<String>> _dateMap = new HashMap<String, Vector<String>>();
    35 
    36         protected void doQuery(String queryText) {
    37                 _dateMap.clear();
    38 
    39                 super.doQuery(queryText);
    40 
    41                 initialiseDateMap(_currentResultSet);
     21       
     22        public SearchGreenstoneByDate() {
     23                super();
    4224        }
    4325
    4426        protected void createResults() {
     27                if(_dateMap.isEmpty()){
     28                        initialiseDateMap(_currentResultSet);
     29                }
    4530                viewByDate(_dateMap, _results);
    4631        }
     
    8368         * output
    8469         */
    85         private void viewByDate(HashMap<String, Vector<String>> dateMap,
     70        private void viewByDate(Map<String, Vector<String>> dateMap,
    8671                        FrameCreator results) {
    8772                Vector<String> theDates = new Vector<String>(dateMap.keySet());
     
    9681                        for (String docID : ids) {
    9782                                ResultDocument rd = _gsdl.getDocument(docID);
    98 
    99                                 // Put the details on a separate frame
    100                                 FrameCreator details = new FrameCreator(rd.getTitle());
    101                                 details.addText(getDetails(rd), null, null, null, true);
    102 
    103                                 results.addText(date + "- " + rd.getTitle(), null, details
    104                                                 .getName(), "getTextFromChildFrame", false);
    105 
    106                                 FrameGraphics.requestRefresh(true);
     83                                addText(rd, results, date + "- " + rd.getTitle());
    10784                        }
    10885                }
  • trunk/src/org/expeditee/greenstone/Greenstone3Connection.java

    r312 r313  
    426426                InputSource is = new InputSource(sr);
    427427                DOMParser p = new DOMParser();
     428
    428429                try {
    429430                        p.parse(is);
  • trunk/src/org/expeditee/greenstone/ResultDocument.java

    r312 r313  
    110110
    111111        public void setTitle(String title) {
    112                 this.title = new String(title);
     112                this.title = removeHTML(title);
    113113                this.retrievedMetadata.add("Title");
    114114        }
     
    226226                return this.retrievedMetadata.contains(metadataTag);
    227227        }
     228       
     229
     230        protected String removeHTML(String s){
     231                return s.replaceAll("&quot;", "\"");
     232        }
    228233
    229234}
  • trunk/src/org/expeditee/items/widgets/DataFrameWidget.java

    r294 r313  
    5454                                addSubject(_dataFrame);
    5555                        } else {
    56                                 // If the dataFrame has not been saved yet because it has just
    57                                 // been
    58                                 // created via TDFC this chart needs to be marked as changed so
    59                                 // it will
    60                                 // be refreshed when the user goes back
    61                                 update();
     56                                /**
     57                                 * If the dataFrame has not been saved yet because it has just
     58                                 * been created via TDFC this widget needs to be marked as
     59                                 * changed so it will be refreshed when the user goes back
     60                                 */
     61                                assert(false);
     62                                //_needsUpdating = true;
     63                                // update();
    6264                        }
    6365                }
     
    98100        public void update() {
    99101                Frame parent = getParentFrame();
    100                 if(parent != null && parent == DisplayIO.getCurrentFrame()){
     102                if (parent != null && parent == DisplayIO.getCurrentFrame()) {
    101103                        refresh();
    102104                }
    103                
     105
    104106                _needsUpdating = true;
    105107        }
     
    115117                clearSubjects();
    116118                setDataFrame(null);
    117                 refresh();
     119                if (oldLink == null) {
     120                        _needsUpdating = true;
     121                } else {
     122                        refresh();
     123                }
    118124        }
    119125
     
    141147        protected void paintInFreeSpace(Graphics g) {
    142148                super.paintInFreeSpace(g);
    143                 g.setFont(((Text)getSource()).getFont());
     149                g.setFont(((Text) getSource()).getFont());
    144150                g.setColor(Color.WHITE);
    145151                g.drawString(this.getClass().getSimpleName(), getX() + 10, getY() + 20);
  • trunk/src/org/expeditee/items/widgets/DataFrameWidget1.java

    r214 r313  
    2525                return stateArgs;
    2626        }
    27        
     27
    2828        @Override
    2929        public void refresh() {
    3030                super.refresh();
    3131                Frame frame = getDataFrame();
    32                 if(frame != null) {
     32                if (frame != null) {
    3333                        _combo.removeAllItems();
    34                         for(Text text: frame.getBodyTextItems(false)) {
     34                        for (Text text : frame.getBodyTextItems(false)) {
    3535                                _combo.addItem(text.getText());
    3636                        }
    37                         _combo.setSelectedIndex(0);
     37                        if (_combo.getItemCount() > 0)
     38                                _combo.setSelectedIndex(0);
    3839                }
    3940        }
Note: See TracChangeset for help on using the changeset viewer.