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; }