KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > search > SearchHit


1 /***************************************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others. All rights reserved. This program and the
3  * accompanying materials are made available under the terms of the Eclipse Public License v1.0
4  * which accompanies this distribution, and is available at
5  * http://www.eclipse.org/legal/epl-v10.html
6  *
7  * Contributors: IBM Corporation - initial API and implementation
8  **************************************************************************************************/

9 package org.eclipse.help.internal.search;
10
11 import java.net.URL JavaDoc;
12
13 import org.eclipse.help.IHelpResource;
14 import org.eclipse.help.IToc;
15 import org.eclipse.help.internal.base.BaseHelpSystem;
16 import org.eclipse.help.search.ISearchEngineResult2;
17
18 /**
19  * A search result containing a document reference, score, summary, etc.
20  */

21 public class SearchHit implements ISearchEngineResult2, Comparable JavaDoc {
22
23     private String JavaDoc href;
24     private String JavaDoc label;
25     private float score;
26     private IToc toc;
27     private String JavaDoc summary;
28     private String JavaDoc id;
29     private String JavaDoc participantId;
30     private boolean isPotentialHit;
31
32     /**
33      * Constructs a new SearchHit.
34      *
35      * @param href the href to the document
36      * @param label a label describing the hit
37      * @param summary a summary paragraph further describing the hit
38      * @param score how relevant this hit is thought to be
39      * @param toc the matching element in the TOC
40      * @param id the unique id of the document
41      * @param participantId the participant the hit came from
42      * @param isPotentialHit this may be a false positive hit
43      */

44     public SearchHit(String JavaDoc href, String JavaDoc label, String JavaDoc summary, float score, IToc toc, String JavaDoc id,
45             String JavaDoc participantId, boolean isPotentialHit) {
46         this.href = href;
47         this.label = label;
48         this.score = score;
49         this.toc = toc;
50         this.summary = summary;
51         this.id = id;
52         this.participantId = participantId;
53         this.isPotentialHit = isPotentialHit;
54     }
55     
56     public int compareTo(Object JavaDoc o) {
57         if (o == this) {
58             return 0;
59         }
60         float s1 = ((SearchHit)this).getScore();
61         float s2 = ((SearchHit)o).getScore();
62         return (s1 < s2 ? 1 : s1 > s2 ? -1 : 0);
63     }
64
65     public boolean equals(Object JavaDoc obj) {
66         if (obj instanceof SearchHit) {
67             if (obj == this) {
68                 return true;
69             }
70             return ((SearchHit)obj).getHref().equals(href);
71         }
72         return false;
73     }
74     
75     public String JavaDoc getHref() {
76         return href;
77     }
78
79     public String JavaDoc getLabel() {
80         return label;
81     }
82
83     public float getScore() {
84         return score;
85     }
86
87     public IToc getToc() {
88         return toc;
89     }
90     
91     public int hashCode() {
92         return href.hashCode();
93     }
94     
95     public void setLabel(String JavaDoc label) {
96         this.label = label;
97     }
98
99     public void setHref(String JavaDoc href) {
100         this.href = href;
101     }
102     
103     public void setPotentialHit(boolean isPotentialHit) {
104         this.isPotentialHit = isPotentialHit;
105     }
106
107     public void setScore(float score) {
108         this.score = score;
109     }
110
111     public void setToc(IToc toc) {
112         this.toc = toc;
113     }
114
115     public String JavaDoc getDescription() {
116         return getSummary();
117     }
118
119     public IHelpResource getCategory() {
120         if (participantId == null)
121             return toc;
122         return BaseHelpSystem.getLocalSearchManager().getParticipantCategory(participantId);
123     }
124
125     public String JavaDoc getSummary() {
126         return summary;
127     }
128
129     public void setSummary(String JavaDoc summary) {
130         this.summary = summary;
131     }
132
133     public boolean getForceExternalWindow() {
134         return participantId == null ? false : true;
135     }
136
137     public String JavaDoc toAbsoluteHref(String JavaDoc href, boolean frames) {
138         return href;
139     }
140
141     public String JavaDoc getId() {
142         return participantId + "/" + id; //$NON-NLS-1$
143
}
144     
145     public String JavaDoc getRawId() {
146         return id;
147     }
148
149     public String JavaDoc getParticipantId() {
150         return participantId;
151     }
152
153     public URL JavaDoc getIconURL() {
154         if (participantId == null)
155             return null;
156         return BaseHelpSystem.getLocalSearchManager().getParticipantIconURL(participantId);
157     }
158
159     public boolean canOpen() {
160         return participantId != null;
161     }
162     
163     public boolean isPotentialHit() {
164         return isPotentialHit;
165     }
166 }
167
Popular Tags