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 TypeFunction nameArguments
hzEcodehdsExec::SrchRepos(hzChain&,hzHttpEvent*,)

Declared in file: hzDissemino.h
Defined in file : hdsExec.cpp

Function Logic:

0:START 1:unknown 2:items 3:items items m_Criteria 4:unknown 5:items pE 6:Return E_NOTFOUND 7:S 8:unknown 9:items rc 10:unknown 11:pE 12:Return E_NOTFOUND 13:pRepos 14:unknown 15:pE 16:Return E_NOTFOUND 17:rc 18:unknown 19:pE 20:Return E_NOTFOUND 21:unknown 22:items pE 23:Return E_NOTFOUND 24:items items S rc 25:unknown 26:items 27:items items 28:unknown 29:items items 30:unknown 31:pRes pPage 32:unknown 33:items items items 34:unknown 35:nStart 36:items items rc 37:unknown 38:items 39:items 40:Return rc

Function body:

hzEcode hdsExec::SrchRepos (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::DocSearch") ;
   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
   hdsPage*        pPage ;         //  Page pointer
   hdbObjRepos*    pRepos ;        //  Repos to look for records if we are not using pages
   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        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("DocSearch ...\n") ;
   //  First tokenize the search criteria
   Result.Clear() ;
   m_Criteria = m_pApp->m_ExecParams[m_FstParam] ;
   if (!pE->m_mapStrings.Exists(m_Criteria))
   {
       errorReport.Printf("%s. No such field as %s\n", __func__, *m_Criteria) ;
       pE->m_appError = "Due to an Internal Error (Field name mismatch) we could not process your request" ;
       return E_NOTFOUND ;
   }
   S = pE->m_mapStrings[m_Criteria] ;
   //  rc = pE->SetVarString(m_Criteria, S) ;
   if (m_Source == "pages")
   {
       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 ;
       }
   }
   else
   {
       //  The source must be a user defined class
       pRepos = m_pApp->m_ADP.GetObjRepos(m_Source) ;
       if (!pRepos)
       {
           //  pE->SetVar(g_Errmsg, "Due to an Internal Error (Repos not located) we could not process your request\n") ;
           pE->m_appError = "Due to an Internal Error (Repos not located) we could not process your request" ;
           return E_NOTFOUND ;
       }
       rc = pRepos->Select(R, *S) ;
       if (rc != E_OK)
       {
           //  pE->SetVar(g_Errmsg, "Due to an Internal Error (Evaluation of select on cache) we could not process your request\n") ;
           pE->m_appError = "Due to an Internal Error (Evaluation of select on cache) 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" ;
   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 ;
}