Skip to main content
summaryrefslogtreecommitdiffstats
blob: f668917584a33bd0c92ff689f026af3f9a15d7f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/***************************************************************************************************
 * Copyright (c) 2000, 2011 IBM Corporation and others. All rights reserved. This program and the
 * accompanying materials are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: IBM Corporation - initial API and implementation
 **************************************************************************************************/
package org.eclipse.help.internal.search;

import java.net.URL;

import org.eclipse.help.IHelpResource;
import org.eclipse.help.IToc;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.search.ISearchEngineResult2;

/**
 * A search result containing a document reference, score, summary, etc.
 */
public class SearchHit implements ISearchEngineResult2, Comparable<SearchHit> {

	private String href;
	private String label;
	private float score;
	private IToc toc;
	private String summary;
	private String id;
	private String participantId;
	private boolean isPotentialHit;

	/**
	 * Constructs a new SearchHit.
	 *
	 * @param href the href to the document
	 * @param label a label describing the hit
	 * @param summary a summary paragraph further describing the hit
	 * @param score how relevant this hit is thought to be
	 * @param toc the matching element in the TOC
	 * @param id the unique id of the document
	 * @param participantId the participant the hit came from
	 * @param isPotentialHit this may be a false positive hit
	 */
	public SearchHit(String href, String label, String summary, float score, IToc toc, String id,
			String participantId, boolean isPotentialHit) {
		this.href = href;
		this.label = label;
		this.score = score;
		this.toc = toc;
		this.summary = summary;
		this.id = id;
		this.participantId = participantId;
		this.isPotentialHit = isPotentialHit;
	}

	@Override
	public int compareTo(SearchHit o) {
		if (o == this) {
			return 0;
		}
		float s1 = this.getScore();
		float s2 = o.getScore();
		return (s1 < s2 ? 1 : s1 > s2 ? -1 : 0);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof SearchHit) {
			if (obj == this) {
				return true;
			}
			return ((SearchHit)obj).getHref().equals(href);
		}
		return false;
	}

	@Override
	public String getHref() {
		return href;
	}

	@Override
	public String getLabel() {
		return label;
	}

	@Override
	public float getScore() {
		return score;
	}

	public IToc getToc() {
		return toc;
	}

	@Override
	public int hashCode() {
		return href.hashCode();
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public void setHref(String href) {
		this.href = href;
	}

	public void setPotentialHit(boolean isPotentialHit) {
		this.isPotentialHit = isPotentialHit;
	}

	public void setScore(float score) {
		this.score = score;
	}

	public void setToc(IToc toc) {
		this.toc = toc;
	}

	@Override
	public String getDescription() {
		return getSummary();
	}

	@Override
	public IHelpResource getCategory() {
		if (participantId == null)
			return toc;
		return BaseHelpSystem.getLocalSearchManager().getParticipantCategory(participantId);
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	@Override
	public boolean getForceExternalWindow() {
		return participantId == null ? false : true;
	}

	@Override
	public String toAbsoluteHref(String href, boolean frames) {
		return href;
	}

	@Override
	public String getId() {
		return participantId + "/" + id; //$NON-NLS-1$
	}

	public String getRawId() {
		return id;
	}

	public String getParticipantId() {
		return participantId;
	}

	@Override
	public URL getIconURL() {
		if (participantId == null)
			return null;
		return BaseHelpSystem.getLocalSearchManager().getParticipantIconURL(participantId);
	}

	@Override
	public boolean canOpen() {
		return participantId != null;
	}

	public boolean isPotentialHit() {
		return isPotentialHit;
	}

}

Back to the top