1 9 package org.eclipse.help.internal.search; 10 11 import java.net.URL ; 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 21 public class SearchHit implements ISearchEngineResult2, Comparable { 22 23 private String href; 24 private String label; 25 private float score; 26 private IToc toc; 27 private String summary; 28 private String id; 29 private String participantId; 30 private boolean isPotentialHit; 31 32 44 public SearchHit(String href, String label, String summary, float score, IToc toc, String id, 45 String 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 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 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 getHref() { 76 return href; 77 } 78 79 public String 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 label) { 96 this.label = label; 97 } 98 99 public void setHref(String 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 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 getSummary() { 126 return summary; 127 } 128 129 public void setSummary(String summary) { 130 this.summary = summary; 131 } 132 133 public boolean getForceExternalWindow() { 134 return participantId == null ? false : true; 135 } 136 137 public String toAbsoluteHref(String href, boolean frames) { 138 return href; 139 } 140 141 public String getId() { 142 return participantId + "/" + id; } 144 145 public String getRawId() { 146 return id; 147 } 148 149 public String getParticipantId() { 150 return participantId; 151 } 152 153 public URL 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 |