searchengine/oss/cl/clucene/src/clucene/highlighter/SimpleHTMLFormatter.cpp
changeset 7 a5fbfefd615f
child 15 cf5c74390b98
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/searchengine/oss/cl/clucene/src/clucene/highlighter/SimpleHTMLFormatter.cpp	Fri Jun 11 14:43:47 2010 +0300
@@ -0,0 +1,38 @@
+#include "CLucene/StdHeader.h"
+#include "SimpleHTMLFormatter.h"
+
+
+CL_NS_DEF2(search,highlight)
+CL_NS_USE(util)
+
+SimpleHTMLFormatter::SimpleHTMLFormatter(const TCHAR* preTag, const TCHAR* postTag):
+	_preTag(stringDuplicate(preTag)),
+	_postTag(stringDuplicate(postTag))
+{
+}
+
+SimpleHTMLFormatter::SimpleHTMLFormatter()
+{
+	_preTag = stringDuplicate(_T("<B>"));
+	_postTag = stringDuplicate(_T("</B>"));
+}
+
+SimpleHTMLFormatter::~SimpleHTMLFormatter() 
+{
+	_CLDELETE_CARRAY(_preTag);
+	_CLDELETE_CARRAY(_postTag);
+}
+
+TCHAR* SimpleHTMLFormatter::highlightTerm(const TCHAR* originalText, const TokenGroup* tokenGroup)
+{
+	if(tokenGroup->getTotalScore()>0){
+		StringBuffer sb;
+		sb.append(_preTag);
+		sb.append(originalText);
+		sb.append(_postTag);
+		return sb.toString();
+	}
+	return stringDuplicate(originalText);
+}
+
+CL_NS_END2