View Javadoc

1   package org.paneris.bibliomania.fti;
2   
3   import java.util.Enumeration;
4   import java.util.Vector;
5   
6   import com.sleepycat.db.DatabaseException;
7   
8   public class HitText {
9     public double score;
10    private Text text;
11    private Vector hitAnchors = new Vector();
12    int areas = 0;
13  
14    HitText(ContextSearchResults results, int areasMax) throws DatabaseException {
15      this(0., results, areasMax);
16    }
17  
18    HitText(double score, ContextSearchResults results, int areasMax)
19      throws DatabaseException {
20      this.score = score;
21      this.text = results.currentText();
22      String lastAnchor = null;
23      Vector areasL = new Vector();
24      for (; areasMax > 0; --areasMax) {
25        String anchor = results.currentAnchor();
26        String area = results.nextArea();
27        if (area == null)
28          break;
29        if (anchor != null) {
30          if (!anchor.equals(lastAnchor) && areasL.size() > 0) {
31            hitAnchors.addElement(new HitAnchor(lastAnchor, areasL));
32            areasL = new Vector();
33          }
34          lastAnchor = anchor;
35        }
36        areasL.addElement(area);
37        ++this.areas;
38      }
39  
40      if (areasL.size() > 0)
41        hitAnchors.addElement(new HitAnchor(lastAnchor, areasL));
42    }
43  
44    public Text getText() {
45      return text;
46    }
47  
48    public Enumeration getHitAnchors() {
49      return hitAnchors.elements();
50    }
51  
52    public void dump() {
53      System.out.println(
54        score + " " + ((org.paneris.bibliomania.Chapter) text).getTitle());
55      for (Enumeration a = getHitAnchors(); a.hasMoreElements();)
56         ((HitAnchor) a.nextElement()).dump();
57    }
58  }