void TDzsHKwBs::AddHits(const PXmlTok& TopicTok, const PBook& Book){ IAssert(TopicTok->IsTag("topic")); // execute query & add hits if (TopicTok->IsSubTag("query")){ // get query string TStr QueryStr=TopicTok->GetTagTok("query")->GetTokStr(false); // search PBixRes BixRes=Book->Search(QueryStr); if (BixRes->IsOk()){ printf("%s - %d\n", QueryStr.CStr(), BixRes->GetHits()); int Hits=BixRes->GetHits(); // retrieve or create <refs> subtag PXmlTok RefsTok; if (Hits>0){ if (TopicTok->IsSubTag("refs")){ RefsTok=TopicTok->GetTagTok("refs"); } else { RefsTok=TXmlTok::New(xsyTag, "refs"); TopicTok->AddSubTok(RefsTok); } } // add hits for (int HitN=0; HitN<Hits; HitN++){ // get hit info TStr SecIdStr; TStr TitleStr; TStr SecStr; TStr CtxStr; BixRes->GetHitInfo( Book, HitN, -1, 100, SecIdStr, TitleStr, SecStr, CtxStr); TStr TitleXmlStr=TXmlLx::GetXmlFromPlainStr(TitleStr); TStr UrlXmlStr=TXmlLx::GetXmlFromPlainStr(SecIdStr); // create <ref> PXmlTok RefTok=TXmlTok::New(xsyTag, "ref"); //RefTok->AddArg("title", TitleXmlStr); RefsTok->AddSubTok(RefTok); // create <title> PXmlTok TitleTok=TXmlTok::New(xsyTag, "title"); RefTok->AddSubTok(TitleTok); PXmlTok TitleStrTok=TXmlTok::New(xsyStr, TitleXmlStr); TitleTok->AddSubTok(TitleStrTok); // create <url> PXmlTok UrlTok=TXmlTok::New(xsyTag, "url"); RefTok->AddSubTok(UrlTok); PXmlTok UrlStrTok=TXmlTok::New(xsyStr, UrlXmlStr); UrlTok->AddSubTok(UrlStrTok); } } } // recurse for (int SubTokN=0; SubTokN<TopicTok->GetSubToks(); SubTokN++){ PXmlTok CurTok=TopicTok->GetSubTok(SubTokN); if (CurTok->IsTag("topic")){ AddHits(CurTok, Book); } } }
///////////////////////////////////////////////// // Dzs-Hierarchical-Keyword-Base bool TDzsHKwBs::IsTopicOk(const PXmlTok& TopicTok){ // <topic> is expected if (!TopicTok->IsTag("topic")){return false;} // <title> is mandatory subtag if (!TopicTok->IsSubTag("title")){return false;} // recurse for (int SubTokN=0; SubTokN<TopicTok->GetSubToks(); SubTokN++){ PXmlTok CurTok=TopicTok->GetSubTok(SubTokN); if (CurTok->IsTag("topic")){ if (!IsTopicOk(CurTok)){return false;} } } return true; }
///////////////////////////////////////////////// // Dzs-Base-Document void TDzsBsDoc::AddDataTokToChA(const PXmlTok& Tok, TChA& ChA){ switch (Tok->GetSym()){ case xsyWs: case xsyStr: case xsyQStr: ChA+=Tok->GetStr(); break; case xsyTag:{ TStr TagNm=Tok->GetStr(); if ((TagNm=="GUID")||(TagNm=="REFF")||(TagNm=="TYPE")||(TagNm=="FILE")){break;} if ((TagNm=="TITLE")||(TagNm=="TOPICTITLE")){break;} ChA+=' '; if ((TagNm=="TITLE")||(TagNm=="TOPICTITLE")){ChA+="<TITLE>";} for (int SubTokN=0; SubTokN<Tok->GetSubToks(); SubTokN++){ AddDataTokToChA(Tok->GetSubTok(SubTokN), ChA);} if ((TagNm=="TITLE")||(TagNm=="TOPICTITLE")){ChA+="</TITLE>";} ChA+=' '; break;} default: Fail; } }
void TDzsHKwBs::SaveHtml(const PXmlTok& TopicTok, const TStr& FPath){ TStr NrFPath=TStr::GetNrFPath(FPath); TStr TitleStr=TopicTok->GetTagTok("title")->GetTokStr(false); TStr FPathSeg=GetFPathSegStr(TitleStr); printf("%s\n", TitleStr.CStr()); TDir::GenDir(NrFPath+FPathSeg); PSOut SOut=TFOut::New(NrFPath+FPathSeg+"/"+"default.htm"); SOut->PutStr("<html>"); SOut->PutDosLn(); SOut->PutDosLn(); // head SOut->PutStr("<head>"); SOut->PutDosLn(); SOut->PutStr("<title>"); SOut->PutStr(TitleStr); SOut->PutStr("</title>"); SOut->PutDosLn(); SOut->PutStr("</head>"); SOut->PutDosLn(); SOut->PutDosLn(); // body-start SOut->PutStr("<body>"); SOut->PutDosLn(); SOut->PutStr("<center><h3>"); SOut->PutStr(TitleStr); SOut->PutStr("</h3></center"); SOut->PutDosLn(); // subtrees SOut->PutStr("<ul>"); SOut->PutDosLn(); for (int SubTokN=0; SubTokN<TopicTok->GetSubToks(); SubTokN++){ PXmlTok CurTok=TopicTok->GetSubTok(SubTokN); if (CurTok->IsTag("topic")){ TStr SubTitleStr=CurTok->GetTagTok("title")->GetTokStr(false); TStr SubFPathSeg=GetFPathSegStr(SubTitleStr); SOut->PutStr("<li>"); SOut->PutStr(TStr("<a href=\"")+SubFPathSeg+"/\">"); SOut->PutStr("<b>"); SOut->PutStr(SubTitleStr); SOut->PutStr("</b>"); SOut->PutStr("</a>"); SOut->PutStr("</li>"); SOut->PutDosLn(); SaveHtml(CurTok, NrFPath+FPathSeg); } } SOut->PutStr("</ul>"); SOut->PutDosLn(); // references if (TopicTok->IsSubTag("refs")){ SOut->PutDosLn(); SOut->PutStr("<hr>"); SOut->PutDosLn(); SOut->PutDosLn(); PXmlTok RefsTok=TopicTok->GetTagTok("refs"); SOut->PutStr("<ul>"); SOut->PutDosLn(); for (int RefTokN=0; RefTokN<RefsTok->GetSubToks(); RefTokN++){ // get <ref> data PXmlTok RefTok=RefsTok->GetSubTok(RefTokN); TStr RefTitleStr=RefTok->GetTagTok("title")->GetTokStr(false); TStr RefUrlStr=RefTok->GetTagTok("url")->GetTokStr(false); // generate <li> SOut->PutStr("<li>"); SOut->PutStr(TStr("<a href=\"")+RefUrlStr+"\">"); SOut->PutStr(RefTitleStr); SOut->PutStr("</a>"); SOut->PutStr("</li>"); SOut->PutDosLn(); } SOut->PutStr("</ul>"); SOut->PutDosLn(); } // footer SOut->PutStr("<center>"); SOut->PutDosLn(); SOut->PutStr("<small>"); SOut->PutStr("Copyright DZS"); SOut->PutStr("</small>"); SOut->PutDosLn(); SOut->PutStr("</center>"); SOut->PutDosLn(); // body-end SOut->PutStr("</body>"); SOut->PutDosLn(); SOut->PutStr("</html>"); SOut->PutDosLn(); }