Conduct a document search and provide a list of document ids found. In all cases the search will either be of an inbuilt resource such as the site's 'indigionous' pages (those defined as <xpage> in the config plus any passive pages), or it will be of a specified class.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdsExec::SrchPages | (hzChain&,hzHttpEvent*,) |
Declared in file: hzDissemino.h
Defined in file : hdsExec.cpp
Function Logic:
Function body:
hzEcode hdsExec::SrchPages (hzChain& errorReport)hzHttpEvent* pE,
{
// Conduct a document search and provide a list of document ids found. In all cases the search will either be of an inbuilt resource such as the
// site's 'indigionous' pages (those defined as <xpage> in the config plus any passive pages), or it will be of a specified class.
//
// Arguments: 1) error The error report chain
// 2) pE The HTTP event pointer
//
// Returns: E_NOTFOUND If there is no session or if the username is not established
// E_OK If the username is established
_hzfunc("hdsExec::SrchPages") ;
hzVect<hdsPage*> Result ; // Pages found
hzVect<uint32_t> res ; // Results
hzChain Z ; // For formulating response
hzToken T ; // Tokenizer for search criteria
hzIntset R ; // Final search result
hdsResource* pRes ; // Resource pointer
hdsPage* pPage ; // Page pointer
hzString m_Action ; // The value of event variable x-action must have (if specified)
hzString m_Source ; // Source to search from (eg indiginous web pages)
hzString m_Criteria ; // The field name containng the search criteria
hzString m_Count ; // Name of the variable used to display the count
hzString m_Found ; // Name of the variable used to display the result (chain of HTML of table defined in format)
hzString V ; // Temp string
hzString S ; // Temp string
uint32_t nCount ; // Loop counter
uint32_t nStart ; // Fetch counter
hzEcode bSelect ; // True if we already have one per token result
hzEcode rc = E_OK ; // Return code
char buf [20]; // For spelling out numbers
if (!pE)
Fatal("No HTTP event supplied\n") ;
errorReport.Printf("SrchPages ...\n") ;
// First tokenize the search criteria
Result.Clear() ;
m_Criteria = m_pApp->m_ExecParams[m_FstParam] ;
V = "srch_pages_criteria" ;
if (!pE->m_mapStrings.Exists(V))
{
errorReport.Printf("%s. No such field as srch_pages_criteria\n", __func__) ;
pE->m_appError = "Due to an Internal Error (Field name mismatch) we could not process your request" ;
return E_NOTFOUND ;
}
S = pE->m_mapStrings[V] ;
// rc = pE->SetVarString(m_Criteria, S) ;
errorReport.Printf("%s. Search page index for [%s]\n", __func__, *S) ;
rc = m_pApp->m_PageIndex.Eval(R, S) ;
if (rc != E_OK)
{
// pE->SetVar(g_Errmsg, "Due to an Internal Error (Evaluation of page index) we could not process your request\n") ;
pE->m_appError = "Due to an Internal Error (Evaluation of page index) we could not process your request" ;
return E_NOTFOUND ;
}
if (!R.Count())
{
Z.Printf("Your search for %s found 0 results. Please try again", *S) ;
pE->m_appError = Z ;
return E_NOTFOUND ;
}
errorReport.Printf("%s. Results are %d pages, error=%s\n", __func__, R.Count(), Err2Txt(rc)) ;
// Fetch records from R
sprintf(buf, "%d", R.Count()) ;
S = buf ;
rc = pE->SetVarString(m_Count, S) ;
if (rc != E_OK)
errorReport.Printf("%s. Could not set var %s to %s\n", __func__, *m_Count, buf) ;
Z << "<div id=\"stdlist\">\n" ;
Z << "<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n" ;
for (nStart = 0;;)
{
R.Fetch(res, nStart, 20);
errorReport.Printf("%s: Fetched %d records (total)\n", __func__, res.Count()) ;
// Lookup titles of pages using numbers
for (nCount = 0; nCount < res.Count() ; nCount++)
{
// pRes = m_pApp->m_PagesName.GetObj(res[nCount]) ;
pRes = m_pApp->m_ResourcesName.GetObj(res[nCount]) ;
pPage = dynamic_cast<hdsPage*>(pRes) ;
if (!pPage)
continue ;
errorReport.Printf("%s: Page No %d is page %p\n", __func__, res[nCount], pPage) ;
Result.Add(pPage) ;
Z.Printf("<tr><td><a href=\"%s\">%s</a></td><td> </td><td><a href=\"%s\">%s</a></td></tr>\n",
*pPage->m_Url, *pPage->m_Title, *pPage->m_Url, *pPage->m_Desc) ;
}
if (res.Count() < 20)
break ;
nStart += 20;
}
Z << "</table>\n" ;
Z << "</div>\n" ;
V = "srch_pages_result" ;
rc = pE->SetVarChain(m_Found, Z) ;
if (rc != E_OK)
errorReport.Printf("%s. Could not set var %s to chain of %d bytes\n", __func__, *m_Found, Z.Size()) ;
errorReport.Printf("%s: Site scanned. %d pages\n", __func__, Result.Count()) ;
return rc ;
}