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