Changeset 1827


Ignore:
Timestamp:
2001-01-11T10:04:04+13:00 (23 years ago)
Author:
paynter
Message:

New version of the java client that handles thesaurus link data
and uses the new cgi arguments to phindcgi.

Location:
trunk/gsdl/src/phind/client
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/phind/client/Phind.java

    r1640 r1827  
    455455    //   3 = get another N phrases into same window
    456456    //   4 = get another N documents into same window
     457    //   5 = get another N thesaurus links into same window
    457458
    458459    ResultBox lookupPhraseOnServer(ResultBox source,
     
    465466    if (queryMode <= 2) {
    466467        r = new ResultBox(this, collection, key, phrase, source);
    467     } else if ((queryMode == 3) || (queryMode == 4)) {
     468    } else if ((queryMode == 3) || (queryMode == 4) || (queryMode == 5)) {
    468469        r = source;
    469470    }
     
    512513    int first_d = 0;
    513514    int last_d = 0;
     515    int first_l = 0;
     516    int last_l = 0;
    514517
    515518    // the initial query
     
    517520      last_e = phraseBlockSize;
    518521      last_d = phraseBlockSize;
    519     }
    520  
     522      last_l = phraseBlockSize;
     523    }
     524
    521525    // add phrases to an existing result set
    522526    else if (queryMode == 3) {
     
    533537    }
    534538
    535     query = query + "&f=" + first_d + "&d=" + last_d
    536                   + "&g=" + first_e + "&e=" + last_e;
     539    // add thesaurus links to existing result set
     540    else if (queryMode == 5) {
     541      first_l = area.nextThesaurusLinkBlock * phraseBlockSize;
     542      area.nextThesaurusLinkBlock++;
     543      last_l = area.nextThesaurusLinkBlock * phraseBlockSize;
     544    }
     545
     546    query = query + "&e=" + first_e + "&f=" + last_e
     547                      + "&h=" + first_d + "&i=" + last_d
     548                      + "&k=" + first_l + "&l=" + last_l;
    537549
    538550    // Send the query to the phindcgi program
     
    658670    String tidy_URL(String address, boolean isCGI) {
    659671
    660     System.out.println("tidy URL: " + address);
     672    // System.out.println("tidy URL: " + address);
    661673   
    662674    // make sure the URL has protocol, host, and file
     
    677689    }
    678690
    679     // if the URL is a cgi script, make sure it has a "?"
     691    // if the URL is a cgi script, make sure it has a "?" in ti,
     692    // and that it ends with a "?" or "&"
    680693    if (isCGI) {
    681694        if (address.indexOf((int) '?') == -1) {
     
    686699    }
    687700
    688 
    689     System.out.println("tidy URL returning: " + address);
    690701    return address;
    691702    }
  • trunk/gsdl/src/phind/client/ResultBox.java

    r1809 r1827  
    7676    int numberOfExpansions;
    7777    int numberOfDocuments;
     78    int numberOfThesaurusLinks;
    7879
    7980    // The number of phrases and documents retrieved, and the number of
    8081    // times the user has requested more phrases or documents.
     82    int expansionsRetrieved;
    8183    int documentsRetrieved;
    82     int expansionsRetrieved;
     84    int thesaurusLinksRetrieved;
    8385    int nextPhraseBlock;
    8486    int nextDocumentBlock;
     87    int nextThesaurusLinkBlock;
    8588   
    86     // just why did i add these variables?
    8789    int mode;
    8890    final int initMode = 0;
     
    115117    numberOfExpansions = -1;
    116118    numberOfDocuments = -1;
     119    numberOfThesaurusLinks = -1;
    117120
    118121    expansionsRetrieved = 0;
    119122    documentsRetrieved = 0;
     123    thesaurusLinksRetrieved = 0;
     124
    120125    nextPhraseBlock = 1;
    121126    nextDocumentBlock = 1;
     127    nextThesaurusLinkBlock = 1;
    122128
    123129
     
    140146
    141147    static String describeContents(String phrase, String c) {
    142     return( "\"" +phrase + "\" in " + c + ".");
     148    return( "\"" + phrase + "\" in " + c + ".");
    143149    }
    144150
     
    157163   
    158164    numberOfExpansions = -1;
     165    numberOfDocuments = -1;
     166    numberOfThesaurusLinks = -1;
     167
    159168    expansionsRetrieved = 0;
    160     numberOfDocuments = -1;
    161169    documentsRetrieved = 0;
     170    thesaurusLinksRetrieved = 0;
    162171    }
    163172
     
    230239
    231240    if (finished) {
    232         c.updateMorePhrasesMarker();
    233         c.updateMoreDocumentsMarker();
     241        c.updateMarkers();
    234242    } else {
    235243        // We haven't finished, give some feedback about progress
     
    273281    }
    274282 
     283    // The <thesaurus> tag
     284    else if (buffer.startsWith("<thesaurus ")) {
     285        item = buffer.substring(0, eol);
     286        buffer = buffer.substring(eol + 1);
     287        addThesaurusTag(item);
     288        return true;
     289    }
     290 
    275291    // The <phinddata> tag introduces the dataset
    276292    else if (buffer.startsWith("<phinddata ")) {
     
    287303    }
    288304   
    289     // The <expansionlist> tag
    290     else if (buffer.startsWith("<expansionlist ")) {
    291 
    292     }
    293  
    294     // The <documentlist> tag
    295     else if (buffer.startsWith("<documentlist ")) {
    296 
    297     }
    298 
    299305    // The <phinderror> tag contains an error message
    300306    else if (buffer.startsWith("<phinderror")) {
     
    307313    // Ignore the piece we've read
    308314    item = buffer.substring(0, eol);
     315    // System.out.println("discarding: " + item);
    309316    buffer = buffer.substring(eol + 1);
    310317    return true;
     
    325332    // System.out.println( "addExpansionListTag: " + line);
    326333
    327     String idStr = "", text = "", tfStr = "", efStr = "", dfStr = "";
    328     int tf = 0, ef = 0, df = 0;
     334    String idStr = "", text = "", tfStr = "", efStr = "", dfStr = "", lfStr = "";
     335    int tf = 0, ef = 0, df = 0, lf = 0;
    329336
    330337    // Break the tag down into its component parts
     
    390397            dfStr = line.substring(0, nextSplit);
    391398            df = Integer.valueOf(dfStr).intValue();
     399            line = line.substring(nextSplit + 1);
     400        } else {
     401            System.err.println("addExpansionListTag: error parsing: " + line);
     402        }
     403        }
     404
     405        // Read the thesaurus link frequency
     406        else if (line.startsWith("lf")) {
     407        line = line.substring(4);
     408        nextSplit = line.indexOf((int) '"');
     409        if (nextSplit >= 1) {
     410            lfStr = line.substring(0, nextSplit);
     411            lf = Integer.valueOf(lfStr).intValue();
    392412            line = line.substring(nextSplit + 1);
    393413        } else {
     
    413433    numberOfExpansions = ef;
    414434    numberOfDocuments = df;
     435    numberOfThesaurusLinks = lf;
    415436    return true;
    416437    }
     
    422443    //   <expansion num="3" id="8421" prefix="PEOPLE and" suffix="" tf="3" df="3"/>
    423444    //   <expansion num="4" id="8696" prefix="" suffix="products" tf="3" df="3"/>
    424     // Create a new ResultItem for display
     445    // Create a new ResultItemPhrase for display
    425446    //
    426447    // Return true if successful, otherwise false.
     
    525546   
    526547    // Create a new ResultItem and add it to the display
    527     ResultItem ri = new ResultItem(idStr, tfStr, dfStr, prefix, body, suffix);
     548    ResultItemPhrase ri = new ResultItemPhrase(idStr, tfStr, dfStr, prefix, body, suffix);
    528549   
    529550    if (c.addResultItem(ri)) {
     
    542563    //   <document num="3" hash="HASH01f08efd8752ad54ca0a99cf" freq="1" title="Tree mixtures"/>
    543564    //
    544     // Create a new ResultItem for display
     565    // Create a new ResultItemDocument for display
    545566    //
    546567    // Return true if successful, otherwise false.
     
    549570
    550571    // System.out.println( "addDocumentTag: " + line + " (" + documentsRetrieved + ")");
    551 
     572   
    552573    String num = "", hash = "", freq = "", title = "";
    553574    line = line.substring(9);
    554 
     575   
    555576    // Break the tag down into its component parts
    556577    int nextSplit;
     
    566587            line = line.substring(nextSplit + 1);
    567588        } else {
    568             System.err.println("ResultBox addExpansionTag: error parsing: " + line);
     589            System.err.println("ResultBox addDocumentTag: error parsing: " + line);
    569590        }
    570591        }
     
    578599            line = line.substring(nextSplit + 1);
    579600        } else {
    580             System.err.println("ResultBox addExpansionTag: error parsing: " + line);
     601            System.err.println("ResultBox addDocumentTag: error parsing: " + line);
    581602        }
    582603        }
     
    590611            line = line.substring(nextSplit + 1);
    591612        } else {
    592             System.err.println("ResultBox addExpansionTag: error parsing: " + line);
     613            System.err.println("ResultBox addDocumentTag: error parsing: " + line);
    593614        }
    594615        }
     
    602623            line = line.substring(nextSplit + 1);
    603624        } else {
    604             System.err.println("ResultBox addExpansionTag: error parsing: " + line);
     625            System.err.println("ResultBox addDocumentTag: error parsing: " + line);
    605626        }
    606627        }
     
    618639   
    619640    // Create a new ResultItem and add it to the display
    620     ResultItem ri = new ResultItem(hash, title, freq);
    621 
     641    ResultItemDocument ri = new ResultItemDocument(hash, title, freq);
     642   
    622643    if (c.addResultItem(ri)) {
    623644        documentsRetrieved++;
     
    627648    return false;
    628649    }
     650
     651
     652    // Add a thesaurus tag
     653    //
     654    // Given a string containing an XML document tag of the form:
     655    //
     656    // <thesaurus num="3" id="36506" tf="0" df="0" type="RT" text="ANGLOPHONE AFRICA"/>
     657    // <thesaurus num="4" id="28724" tf="0" df="0" type="RT" text="FRANCOPHONE AFRICA"/>
     658    //
     659    // Create a new ResultItemLink for display
     660    //
     661    // Return true if successful, otherwise false.
     662
     663    boolean addThesaurusTag( String line ) {
     664   
     665    // System.out.println( "addThesaurusTag: " + line + " (" + thesaurusLinksRetrieved + ")");
     666
     667    String num = "", id = "", tf = "", df = "", type = "", text = "";
     668    line = line.substring(10);
     669
     670    // Break the tag down into its component parts
     671    int nextSplit;
     672        while (line.length() > 0) {
     673        line = line.trim();
     674
     675        // Read the expansion number
     676        if (line.startsWith("num")) {
     677        line = line.substring(5);
     678        nextSplit = line.indexOf((int) '"');
     679        if (nextSplit >= 1) {
     680            num = line.substring(0, nextSplit);
     681            line = line.substring(nextSplit + 1);
     682        } else {
     683            System.err.println("ResultBox addThesaurusTag: error parsing: " + line);
     684        }
     685        }
     686
     687        // Read the phrase ID
     688        else if (line.startsWith("id")) {
     689        line = line.substring(4);
     690        nextSplit = line.indexOf((int) '"');
     691        if (nextSplit >= 1) {
     692            id = line.substring(0, nextSplit);
     693            line = line.substring(nextSplit + 1);
     694        } else {
     695            System.err.println("ResultBox addThesaurusTag: error parsing: " + line);
     696        }
     697        }
     698
     699        // Read the phrase link type
     700        else if (line.startsWith("type")) {
     701        line = line.substring(6);
     702        nextSplit = line.indexOf((int) '"');
     703        if (nextSplit >= 1) {
     704            type = line.substring(0, nextSplit);
     705            line = line.substring(nextSplit + 1);
     706        } else {
     707            System.err.println("ResultBox addThesaurusTag: error parsing: " + line);
     708        }
     709        }
     710
     711
     712        // Read the phrase text
     713        else if (line.startsWith("text")) {
     714        line = line.substring(6);
     715        nextSplit = line.indexOf((int) '"');
     716        if (nextSplit >= 1) {
     717            text = line.substring(0, nextSplit);
     718            line = line.substring(nextSplit + 1);
     719        } else {
     720            System.err.println("ResultBox addThesaurusTag: error parsing: " + line);
     721        }
     722        }
     723
     724        // Read the frequency
     725        else if (line.startsWith("tf")) {
     726        line = line.substring(4);
     727        nextSplit = line.indexOf((int) '"');
     728        if (nextSplit >= 1) {
     729            tf = line.substring(0, nextSplit);
     730            line = line.substring(nextSplit + 1);
     731        } else {
     732            System.err.println("ResultBox addExpansionTag: error parsing: " + line);
     733        }
     734        }
     735
     736        // Read the document frequency
     737        else if (line.startsWith("df")) {
     738        line = line.substring(4);
     739        nextSplit = line.indexOf((int) '"');
     740        if (nextSplit >= 1) {
     741            df = line.substring(0, nextSplit);
     742            line = line.substring(nextSplit + 1);
     743        } else {
     744            System.err.println("ResultBox addExpansionTag: error parsing: " + line);
     745        }
     746        }
     747
     748
     749        // Read some other tag or close the string off
     750        else {
     751        nextSplit = line.indexOf((int) ' ');
     752        if (nextSplit >= 1) {
     753            line = line.substring(nextSplit + 1);
     754        } else {
     755            line = "";
     756        }
     757        }
     758    }
     759   
     760    // Create a new ResultItem and add it to the display
     761    ResultItemLink ri = new ResultItemLink(id, text, type, tf, df);
     762
     763    if (c.addResultItem(ri)) {
     764        thesaurusLinksRetrieved++;
     765        return true;
     766    }
     767   
     768    return false;
     769    }
    629770}
    630771
  • trunk/gsdl/src/phind/client/ResultCanvas.java

    r1682 r1827  
    3131
    3232The results of a query are displayed on a ResultCanvas object.  Each
    33 line of the result is stored in a ResultItem, and the ResultCanvas
     33entry in the result list is stored in a ResultItem, and the ResultCanvas
    3434contains a Vector of ResultItems.
    3535
     
    108108
    109109
    110     // add a new item of input.
    111     // return true if successful, otherwise false.
     110    // Add a new search result.
     111    // Return true if successful, otherwise false.
    112112    boolean addResultItem( ResultItem item ) {
    113113 
     
    120120           ((item.kind > ((ResultItem) phrases.elementAt(index)).kind) ||
    121121        ((item.kind == ((ResultItem) phrases.elementAt(index)).kind) &&
    122          (item.freq <= ((ResultItem) phrases.elementAt(index)).freq)))) {
     122         (item.frequency <= ((ResultItem) phrases.elementAt(index)).frequency)))) {
    123123        index++;
    124124    }
     
    128128    }
    129129
     130
     131    // Update more phrases/documents/links markers
     132    void updateMarkers() {
     133    updateMorePhrasesMarker();
     134    updateMoreDocumentsMarker();
     135    updateMoreLinksMarker();
     136    }
    130137
    131138    // Make sure the more Phrases item only appears in the list
     
    140147    while (!found && (index < numberOfPhrases)) {
    141148        if (((ResultItem) phrases.elementAt(index)).isMorePhrases()) {
    142         // System.out.println("found marker at: " + index + " of " + numberOfPhrases);
    143149        found = true;
    144150        } else {
     
    149155    if (parent.expansionsRetrieved == parent.numberOfExpansions) {
    150156        // there should be no marker
    151         // System.out.println("No marker needed");
    152157        if (found) {
    153         // System.out.println("Remove marker");
    154158        phrases.removeElementAt(index);
    155159        numberOfPhrases--;
     
    157161
    158162    } else if (parent.expansionsRetrieved < parent.numberOfExpansions) {
    159         // there should be a marker
    160         // System.out.println("Needs marker");
    161 
    162163        if (!found) {
    163         // System.out.println("Add marker");
    164         ResultItem ri = new ResultItem(ResultItem.morePhrases, parent.searchKey);
     164        ResultItem ri = new ResultItem(ResultItem.morePhrases);
    165165        addResultItem(ri);
    166166        }
     
    195195        // there should be a marker
    196196        if (!found) {
    197         ResultItem ri = new ResultItem(ResultItem.moreDocuments, parent.searchKey);
     197        ResultItem ri = new ResultItem(ResultItem.moreDocuments);
     198        addResultItem(ri);
     199        }
     200    }
     201    }
     202
     203     
     204    // Make sure the more links marker appears when required
     205    void updateMoreLinksMarker() {
     206   
     207    System.out.println("updateMoreLinksMarker() ");
     208    System.out.println("retreived: " + parent.thesaurusLinksRetrieved);
     209    System.out.println("total: " + parent.numberOfThesaurusLinks);
     210
     211    // look for a marker
     212    boolean found = false;
     213    int index = 0;
     214    while (!found && (index < numberOfPhrases)) {
     215        if (((ResultItem) phrases.elementAt(index)).isMoreLinks()) {
     216        found = true;
     217        } else {
     218        index++;
     219        }
     220    }
     221
     222    if (parent.thesaurusLinksRetrieved == parent.numberOfThesaurusLinks) {
     223        // there should be no marker
     224        if (found) {
     225        phrases.removeElementAt(index);
     226        numberOfPhrases--;
     227        }
     228
     229    } else if (parent.thesaurusLinksRetrieved < parent.numberOfThesaurusLinks) {
     230        // there should be a marker
     231        if (!found) {
     232        ResultItem ri = new ResultItem(ResultItem.moreLinks);
    198233        addResultItem(ri);
    199234        }
     
    270305        + ((rightMargin - leftMargin
    271306        - g.getFontMetrics().stringWidth(parent.searchPhrase)) / 2);
     307
     308    String body, prefix, suffix;
    272309   
    273310    for (i = scrollValue;
     
    290327        // Draw the item
    291328
     329        // Draw a phrase item
    292330        if (result.isPhrase()) {
    293         // The item is a Phrase
    294         tab = center - g.getFontMetrics().stringWidth(result.prefix) - space;
    295         g.drawString(result.prefix, tab, y);
     331        prefix = result.prefixText();
     332        body = result.mainText();
     333        suffix = result.suffixText();
     334       
     335        g.setColor(Color.black);
     336        g.setFont(areaPlain);
     337        tab = center - g.getFontMetrics().stringWidth(prefix) - space;
     338        g.drawString(prefix, tab, y);
     339       
    296340        g.setFont(areaBold);
    297         g.drawString(result.body, center, y);
    298         tab = center + space + g.getFontMetrics().stringWidth(result.body);
     341        g.drawString(body, center, y);
     342        tab = center + space + g.getFontMetrics().stringWidth(body);
     343       
    299344        g.setFont(areaPlain);
    300         g.drawString(result.suffix, tab, y);
     345        g.drawString(suffix, tab, y);
    301346   
    302         } else if (result.isDocument()){
    303         // The item is a URL
     347        }
     348
     349        // Draw a document item
     350        else if (result.isDocument()){
     351        body = result.mainText();
     352
    304353        g.setFont(areaPlain);
    305354        g.setColor(Color.blue);
    306         tab = (rightMargin - g.getFontMetrics().stringWidth(result.body)) / 2;
    307         g.drawString(result.body, tab, y);
     355        tab = (rightMargin - g.getFontMetrics().stringWidth(body)) / 2;
     356        g.drawString(body, tab, y);
     357     
     358        }
     359   
     360        // Draw a thesaurus link item
     361        else if (result.isLink()){
     362        prefix = result.prefixText() + ":";
     363        body = result.mainText();
     364
     365        g.setFont(areaPlain);
     366        g.setColor(new Color(0, 100, 0));
     367        tab = center - g.getFontMetrics().stringWidth(prefix) - space;
     368        // tab = margin + margin - g.getFontMetrics().stringWidth(prefix);
     369        g.drawString(prefix, tab, y);
     370
     371        g.setFont(areaBold);
     372        g.drawString(body, center, y);
     373     
     374        }
     375       
     376        // Draw a "more phrases/documents/links" marker
     377        else if (result.isMorePhrases()
     378             || result.isMoreDocuments()
     379             || result.isMoreLinks()){
     380        body = result.mainText();
     381       
     382        if (result.isMorePhrases()) {
     383            g.setColor(new Color(255, 200, 200));
     384        } else {
     385            g.setColor(new Color(150, 193, 156));
     386        }
     387        g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing);
     388
    308389        g.setColor(Color.black);
    309      
    310         } else if (result.isMorePhrases()){
    311         // The item is a More documents marker
    312         g.setColor(new Color(255, 200, 200));
    313         g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing);
    314         g.setColor(Color.black);
    315 
    316390        g.setFont(areaPlain);
    317         tab = (rightMargin - g.getFontMetrics().stringWidth("Get more phrases")) / 2;
    318         g.drawString("Get more phrases", tab, y);
    319 
    320         } else if (result.isMoreDocuments()){
    321         // The item is a More documents marker
    322         g.setColor(new Color(150, 193, 156));
    323         g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing);
    324         g.setColor(Color.black);
    325 
    326         g.setFont(areaPlain);
    327         tab = (rightMargin - g.getFontMetrics().stringWidth("Get more documents")) / 2;
    328         g.drawString("Get more documents", tab, y);
    329 
    330         }
    331 
     391        tab = (rightMargin - g.getFontMetrics().stringWidth(body)) / 2;
     392        g.drawString(body, tab, y);
     393        }
    332394    }
    333395
     
    355417
    356418        // Write the document frequency
    357         if ((result.documents > 1) || result.isPhrase()) {
    358         g.drawString(" " + Integer.toString(result.documents), firstColumn, y);
     419        if (result.docsText().length() > 0) {
     420        g.drawString(" " + result.docsText(), firstColumn, y);
    359421        }
    360422
    361423        // Write the term frequency
    362         if (result.freq > 0) {
    363         g.drawString(" " + Integer.toString(result.freq), secondColumn, y);
     424        if (result.freqText().length() > 0) {
     425        g.drawString(" " + result.freqText(), secondColumn, y);
    364426        }
    365427    }
     
    407469        ResultItem item = (ResultItem) phrases.elementAt(itemSelected);
    408470
    409         // System.out.println("Select: " + String.valueOf(rowSelected) );
    410471        if (itemSelected <= numberOfPhrases) {
    411472   
    412         // What do we do with the event?
    413         // If user clicks on a phrase, we expand the phrase
    414         // or send the phrase to a search engine (right click)
    415 
     473        //User clicks on a phrase
    416474        if (item.isPhrase()) {
    417             // Expand the phrase
    418475
    419476            phraseSelected = itemSelected;
    420477            update(getGraphics());
    421478     
    422             parent.lookupPhrase(item.rule, item.toString(), 2);
    423 
     479            parent.lookupPhrase(item.hiddenText(), item.toString(), 2);
     480
     481            // If meta key is held down, send query to search engine
    424482            if (event.metaDown()) {
    425             // Also send to search engine
    426483            if (phind.search_url.equals("none") || phind.search_url.equals("")) {
    427484                System.out.println("No searching in this collection");
     
    435492                System.out.println("URL error: " + e.toString());
    436493                }
    437             } 
     494            }
    438495            }
    439496
    440         } else if (item.isDocument()) {
    441             // The user clicks on a URL; display it.
     497        }
     498
     499        // Click on a thesaurus link
     500        else if (item.isLink()) {
     501            phraseSelected = itemSelected;
     502            update(getGraphics());
     503            parent.lookupPhrase(item.hiddenText(), item.toString(), 2);
     504        }
     505
     506        // The user clicks on a URL; display it.
     507        else if (item.isDocument()) {
    442508            phraseSelected = itemSelected;
    443509            update(getGraphics());
     
    447513            String address = phind.library_address
    448514                + "a=d&c=" + phind.collection
    449                 + "&d=" + item.rule
     515                + "&d=" + item.hiddenText()
    450516                + "&q=" + parent.searchPhrase.replace(' ', '+');
    451517            url = new URL(address);
    452518            System.out.println("URL selected: " + url.toString());
    453             phind.getAppletContext().showDocument(url);
     519            phind.getAppletContext().showDocument(url, "phinddoc");
    454520            } catch (Exception e) {
    455521            System.out.println("URL error: " + e.toString());
    456522            }
    457 
    458         } else if (item.isMorePhrases()){
    459             // The user clicks on a "get more phrases" marker.
    460             // We have to send a new query to the host
     523        }
     524         
     525        // When the user clicks on "get more phrases" or other marker,
     526        // we have to send a new query to the host
     527        else if (item.isMorePhrases()){
    461528            parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 3);
    462 
    463529        } else if (item.isMoreDocuments()){
    464530            parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 4);
     531        } else if (item.isMoreLinks()){
     532            parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 5);
    465533
    466534
  • trunk/gsdl/src/phind/client/ResultItem.java

    r1626 r1827  
    11/**********************************************************************
    22 *
    3  * ResultBox.java -- a list of phrases in the Phind java interface
     3 * ResultItemDocument.java -- a result in the Phind applet
    44 *
    5  * Copyright 1997-2000 Gordon W. Paynter
     5 * Copyright 2000 Gordon W. Paynter
    66 * Copyright 2000 The New Zealand Digital Library Project
    77 *
     
    3030This class is used in the Phind java applet (Phind.java).
    3131
    32 A result item object holds the data describing a single line returned from
    33 a query to the server.  It therefore contains either information describing
    34 a phrase or a URL.
     32A result item holds the data describing a single line returned from a phind
     33query.  The complex functionality of phrase and URL items is implemented in
     34subclasses; the base class handles simpler cases like the "get more phrases"
     35marker.
    3536
    3637**********************************************************************/
     
    3940public class ResultItem {
    4041
    41     // There are four kinds of item
    42     //   1. a phrase
    43     //   2. a document (or URL)
    44     //   3. a "get more phrases" marker
     42    // There are several kinds of ResultItem
     43    //   1. a phrase (expansion)
     44    //   2. a "get more phrases" marker
     45    //   3. a document (or URL)
    4546    //   4. a "get more documents" marker
    46     // These should possibly be written as subclasses of a ResultItem
    47     // superclass, but I cannot be bothered rewriting it for now.
     47    //   5. a thesaurus link
     48    //   6. a "get more thesaurus links" marker
    4849
    49     final static int phraseItem = 1;
    50     final static int morePhrases = 2;
    51     final static int documentItem = 3;
    52     final static int moreDocuments = 4;
     50    final static int linkItem = 1;
     51    final static int moreLinks = 2;
     52    final static int phraseItem = 3;
     53    final static int morePhrases = 4;
     54    final static int documentItem = 5;
     55    final static int moreDocuments = 6;
     56    final static int unknownResultItem = 9;
    5357
    54     // What kind is this item:
    55     int kind;
     58    // A text string describing the item
     59    String text = "Generic ResultItem";
    5660
    57     // The "rule" is the unique identifier of this item.  For a phrase,
    58     // this is its "phrase number", and is also stored as a number in
    59     // symbol.  For a document it is the document's OID (hash) value.
    60     String rule;
    61     int symbol;
     61    // The kind of the item
     62    int kind = unknownResultItem;
    6263
    63     // The term frequency of the item
    64     int freq;
    65 
    66     // The document frequency of the item
    67     int documents;
    68 
    69     // Can this item be expanded?  ---- obsolete?
    70     int expansion;
    71 
    72     // When the item is a phrase, the text of the item is split into a
    73     // prefix, body, and suffix.  The body is the search term and the
    74     // prefix and suffix the surrounding text in the new phrase.
    75     // When the item is a document, its title is stored in the body.
    76     String prefix;
    77     String body;
    78     String suffix;
     64    // The frequency of the item
     65    int frequency = 0;
    7966
    8067
    81     // Create a ResultItem for a phrase
    82     ResultItem(String r, String f, String d,
    83            String p, String b, String s) {
    84 
    85     kind = phraseItem;
    86     rule = r;
    87     symbol = Integer.valueOf(rule).intValue();
    88 
    89     freq = Integer.valueOf(f).intValue();
    90     documents = Integer.valueOf(d).intValue();
    91     expansion = 0;
    92 
    93     prefix = p;
    94     body = b;
    95     suffix = s;
    96 
     68    // Create a blank ResultItem
     69    ResultItem() {
     70    text = "Unknown result type";
     71    kind = unknownResultItem;
     72    frequency = 0;
    9773    }
    9874
     75    // Create a new ResultItem of some given kind
     76    ResultItem(int newKind) {
     77    kind = newKind;
     78    frequency = 0;
    9979
    100     // Create a ResultItem for a document
    101     ResultItem(String hash, String title, String df) {
    102    
    103     kind = documentItem;
    104     rule = hash;
    105     body = title;
    106     documents = Integer.valueOf(df).intValue();
    107    
    108     // not needed for a document
    109     symbol = 0;
    110     freq = 0;
    111     expansion = 0;
    112     prefix = "";
    113     suffix = "";
     80    if (kind == moreLinks) {
     81        text = "get more thesaurus links";
     82    } else if (kind == morePhrases) {
     83        text = "get more phrases";
     84    } else if (kind == moreDocuments) {
     85        text = "get more documents";
     86    } else {
     87        text = "Unknown result type";
     88    }
    11489    }
    11590
     91    // Test the type of a ResultItem
     92    public boolean isLink() { return false; }
     93    public boolean isMoreLinks() { return (kind == moreLinks); }
     94    public boolean isPhrase() { return false; }
     95    public boolean isMorePhrases() { return (kind == morePhrases); }
     96    public boolean isDocument() { return false; }
     97    public boolean isMoreDocuments() { return (kind == moreDocuments); }
    11698
    117     // Create an empty ResultItem of a given kind
    118     ResultItem(int k, String r) {
     99    // Return the bare text of the item
     100    public String toString() { return(text); }
    119101
    120     kind = k;
    121 
    122     rule = r;
    123     symbol = -1;
    124 
    125     freq = 0;
    126     expansion = 0;
    127     documents = 0;
    128 
    129     prefix = "";
    130     body = "";
    131     suffix = "";
    132     }
    133 
    134     // Return the full phrase described by the item.
    135     public String toString() {
    136     String result = "";
    137     if (!prefix.equals("")) result = prefix.replace(' ', '+') + "+";
    138     result += body.replace(' ', '+');
    139     if (!suffix.equals("")) result += "+" + suffix.replace(' ', '+');
    140     return(result.trim());
    141     }
    142 
    143     // Is the item a phrase?
    144     public boolean isPhrase() {
    145     return (kind == phraseItem);
    146     }
    147 
    148     // Is the item a document?
    149     public boolean isDocument() {
    150     return (kind == documentItem);
    151     }
    152 
    153     public boolean isMorePhrases() {
    154     return (kind == morePhrases);
    155     }
    156 
    157     public boolean isMoreDocuments() {
    158     return (kind == moreDocuments);
    159     }
    160 
    161 
     102    // Return the text of the item components
     103    public String mainText() { return text; }
     104    public String freqText() { return Integer.toString(frequency); }
     105    public String docsText() { return ""; }
     106    public String prefixText() { return ""; }
     107    public String suffixText() { return ""; }
     108    public String hiddenText() { return ""; }
    162109}
    163110
    164 
  • trunk/gsdl/src/phind/client/ResultTitle.java

    r1681 r1827  
    103103 
    104104    // Construct the description phrase
     105    String links = "";
     106    if (parent.numberOfThesaurusLinks <= 0) {
     107    links = "";
     108    } else if (parent.numberOfThesaurusLinks == 1) {
     109    links = "1 link";
     110    } else if (parent.thesaurusLinksRetrieved == parent.numberOfThesaurusLinks) {
     111    links = parent.numberOfThesaurusLinks + " links";
     112    } else {
     113    links = parent.thesaurusLinksRetrieved + " of "
     114        + parent.numberOfThesaurusLinks + " links";
     115    }
     116
    105117    String expansions = "";
    106118    if (parent.numberOfExpansions <= 0) {
    107       expansions = "no phrases";
     119    expansions = "no phrases";
    108120    } else if (parent.numberOfExpansions == 1) {
    109       expansions = "1 phrase";
     121    expansions = "1 phrase";
    110122    } else if (parent.expansionsRetrieved == parent.numberOfExpansions) {
    111       expansions = parent.numberOfExpansions + " phrases";
     123    expansions = parent.numberOfExpansions + " phrases";
    112124    } else {
    113       expansions = "first " + parent.expansionsRetrieved + " of " + parent.numberOfExpansions + " phrases";
     125    expansions = parent.expansionsRetrieved + " of "
     126        + parent.numberOfExpansions + " phrases";
    114127    }
    115128
    116129    String documents = "";
    117130    if (parent.numberOfDocuments <= 0) {
    118       documents = "no documents";
     131    documents = "no documents";
    119132    } else if (parent.documentsRetrieved == 1) {
    120       documents = "1 document";
     133    documents = "1 document";
    121134    } else if (parent.documentsRetrieved == parent.numberOfDocuments) {
    122       documents = parent.numberOfDocuments + " documents";
     135    documents = parent.numberOfDocuments + " documents";
    123136    } else {
    124       documents = "first " + parent.documentsRetrieved + " of " + parent.numberOfDocuments + " documents";
     137    documents = parent.documentsRetrieved + " of "
     138        + parent.numberOfDocuments + " documents";
    125139    }
     140
     141    String status = "(";
     142    if (parent.numberOfThesaurusLinks > 0) {
     143    status = status + links + ", ";
     144    }
     145    status = status + links + expansions + ", " + documents + ")";
     146
    126147
    127148    // Draw the text
     
    131152
    132153    g.setFont(plain);
    133     String status = "(" + expansions + ", " + documents + ")";
    134154    g.drawString(status, tab, y);
    135155    tab = tab + g.getFontMetrics().stringWidth(status);
Note: See TracChangeset for help on using the changeset viewer.