wiki test: fixed result text

git-svn-id: trunk@35752 -
This commit is contained in:
mattias 2012-03-05 20:53:46 +00:00
parent abe3e7cd8b
commit a06225b2c3
2 changed files with 34 additions and 16 deletions

View File

@ -259,6 +259,8 @@ function CompareW2HPageForScore(Page1, Page2: Pointer): integer;
function TextToHTMLSnipped(Txt: string; LoCaseStringsToHighlight: TStrings;
MaxUTF8Length: integer): string;
function dbgs(t: TWHTextNodeType): string; overload;
procedure Test_TextToHTMLSnipped;
implementation
@ -448,6 +450,12 @@ begin
end;
end;
function dbgs(t: TWHTextNodeType): string;
begin
Result:='';
writestr(Result,t);
end;
procedure Test_TextToHTMLSnipped;
procedure t(Txt, LoCaseHighlights: string; MaxUTF8Length: integer; Expected: string);
@ -1350,8 +1358,8 @@ begin
Page:=TW2HelpPage(FoundPages[i]);
Node:=Page.GetNodeHighestScore(Query,Scoring);
s:='<div class="wikiSearchResultItem">'+FoundNodeToHTMLSnippet(Page,Node,Query)+'</div>'+LineEnding;
HTML+=s;
//debugln(['TWikiHelp.TestSearch Score=',Page.Score,' HTML="',s,'"']);
HTML+=s;
end;
HTML+='</body>'+LineEnding
+'</html>'+LineEnding;
@ -1381,10 +1389,23 @@ begin
+' alt="'+StrToXMLValue(aPage.WikiPage.Title)+'"'
+'>'
+TextToHTMLSnipped(aPage.WikiPage.Title,aQuery.LoPhrases,200)+'</a><br>'+LineEnding;
if aNode=nil then begin
// get the first node with some text
aNode:=aPage.TextRoot;
while (aNode<>nil) and (UTF8Trim(aNode.Txt)='') do
aNode:=aNode.Next;
end;
if aNode<>nil then begin
//debugln(['TWikiHelp.FoundNodeToHTMLSnippet ',dbgs(aNode.Typ),' Txt="'+dbgstr(ANode.Txt)+'"']);
HeaderNode:=aNode;
while (HeaderNode<>nil) and (HeaderNode.Typ<>whnLink) do
while (HeaderNode<>nil) and (HeaderNode.Typ<>whnHeader) do
HeaderNode:=HeaderNode.Previous;
if aNode=HeaderNode then begin
// get the first node after the header with some text
repeat
aNode:=aNode.Next;
until (aNode=nil) or (UTF8Trim(aNode.Txt)<>'');
end;
if HeaderNode<>nil then begin
// add a direct link to the sub topic
Result+='Topic <a href="'+StrToXMLValue(aPage.WikiDocumentName+'#'+WikiHeaderToLink(HeaderNode.Txt))+'"'
@ -1393,7 +1414,7 @@ begin
+'>'
+TextToHTMLSnipped(HeaderNode.Txt,aQuery.LoPhrases,200)+'</a>: ';
end;
if HeaderNode<>aNode then begin
if aNode<>nil then begin
// add text
Result+=TextToHTMLSnipped(aNode.Txt,aQuery.LoPhrases,200);
end;

View File

@ -33,9 +33,7 @@ type
SearchLabel: TLabel;
Splitter1: TSplitter;
Timer1: TTimer;
function DataProviderCanHandle(Sender: TObject; const URL: string): Boolean;
procedure DataProviderCheckURL(Sender: TObject; const URL: string;
var Available: Boolean; var ContentType: string);
function DataProviderCanHandle(Sender: TObject; const {%H-}URL: string): Boolean;
procedure DataProviderGetImage(Sender: TIpHtmlNode; const URL: string;
var Picture: TPicture);
procedure FormCreate(Sender: TObject);
@ -105,7 +103,6 @@ begin
PageIpHtmlPanel.DataProvider:=FURLDataProvider;
FURLDataProvider.OnCanHandle:=@DataProviderCanHandle;
FURLDataProvider.OnGetImage:=@DataProviderGetImage;
FURLDataProvider.OnCheckURL:=@DataProviderCheckURL;
WikiHelp:=TWikiHelp.Create(nil);
WikiHelp.XMLDirectory:=SetDirSeparators('../wikixml');
@ -134,14 +131,6 @@ begin
Result:=false;
end;
procedure TWikiSearchDemoForm.DataProviderCheckURL(Sender: TObject;
const URL: string; var Available: Boolean; var ContentType: string);
begin
debugln(['TWikiSearchDemoForm.DataProviderCheckURL URL=',URL]);
Available:=false;
ContentType:='';
end;
procedure TWikiSearchDemoForm.DataProviderGetImage(Sender: TIpHtmlNode;
const URL: string; var Picture: TPicture);
var
@ -195,6 +184,8 @@ var
Panel: TIpHtmlPanel;
ms: TMemoryStream;
Src: String;
DocumentName: String;
p: SizeInt;
begin
Panel:=Sender as TIpHtmlPanel;
HotNode:=Panel.HotNode;
@ -210,7 +201,13 @@ begin
ms:=TMemoryStream.Create;
try
try
WikiHelp.SavePageToStream(href,ms);
DocumentName:=HRef;
p:=Pos('#',DocumentName);
if p>0 then begin
DocumentName:=LeftStr(DocumentName,p-1);
// ToDo: anchor
end;
WikiHelp.SavePageToStream(DocumentName,ms);
ms.Position:=0;
LoadHTML(PageIpHtmlPanel,ms);
except