Esempio n. 1
0
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);
    }
  }
}
Esempio n. 2
0
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();
}
TStr GetStrArg(const PXmlTok& QueryXml, const TStr& TagPath, const TStr& ArgNm, const TStr& DfVal)
{
	PXmlTok XmlTok = QueryXml->GetTagTok(TagPath);
	if (XmlTok.Empty()) return DfVal;
	return XmlTok->GetArgVal(ArgNm, DfVal);
}