01: package org.apache.lucene.search.highlight;
02:
03: /**
04: * Copyright 2002-2004 The Apache Software Foundation
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: /**
20: * Simple {@link Formatter} implementation to highlight terms with a pre and post tag
21: * @author MAHarwood
22: *
23: */
24: public class SimpleHTMLFormatter implements Formatter {
25: String preTag;
26: String postTag;
27:
28: public SimpleHTMLFormatter(String preTag, String postTag) {
29: this .preTag = preTag;
30: this .postTag = postTag;
31: }
32:
33: /**
34: * Default constructor uses HTML: <B> tags to markup terms
35: *
36: **/
37: public SimpleHTMLFormatter() {
38: this .preTag = "<B>";
39: this .postTag = "</B>";
40: }
41:
42: /* (non-Javadoc)
43: * @see org.apache.lucene.search.highlight.Formatter#highlightTerm(java.lang.String, org.apache.lucene.search.highlight.TokenGroup)
44: */
45: public String highlightTerm(String originalText,
46: TokenGroup tokenGroup) {
47: StringBuffer returnBuffer;
48: if (tokenGroup.getTotalScore() > 0) {
49: returnBuffer = new StringBuffer();
50: returnBuffer.append(preTag);
51: returnBuffer.append(originalText);
52: returnBuffer.append(postTag);
53: return returnBuffer.toString();
54: }
55: return originalText;
56: }
57: }
|