Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
6.6 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. NetSearchConfig.cpp
  5. Abstract:
  6. Implements the class CSearchResultList that contains methods for traversing the elements
  7. of XML file that contains the results returned by a search engine. A sample results XML file
  8. if shown here -
  9. <ResultList xmlns="x-schema:ResultListSchema1.xdr">
  10. <ResultItem
  11. Title="What if I've upgraded from Windows 95 to Windows 98?"
  12. URI="http://gsadevnet/support/windows/InProductHelp98/lic_keep_old_copy.asp"
  13. ContentType="7"
  14. Rank="96"
  15. Description="Online version of our in-product help."
  16. DateLastModified="08/04/1999 19:48:10" />
  17. </ResultList>
  18. Revision History:
  19. a-prakac created 10/24/200
  20. ********************************************************************/
  21. #include "stdafx.h"
  22. static const WCHAR g_wszMutexName [] = L"PCH_SEARCHRESULTSCONFIG";
  23. /////////////////////////////////////////////////////////////////////
  24. CFG_BEGIN_FIELDS_MAP(CSearchResultList::CSearchItem)
  25. CFG_VALUE( wstring, m_strSearchItem ),
  26. CFG_END_FIELDS_MAP()
  27. CFG_BEGIN_CHILD_MAP(CSearchResultList::CSearchItem)
  28. CFG_END_CHILD_MAP()
  29. //DEFINE_CFG_OBJECT(CSearchResultList::CSearchItem,L"SearchItem")
  30. DEFINE_CFG_OBJECT(CSearchResultList::CSearchItem,L"SearchTerm")
  31. DEFINE_CONFIG_METHODS__NOCHILD(CSearchResultList::CSearchItem)
  32. /////////////////////////////////////////////////////////////////////
  33. CFG_BEGIN_FIELDS_MAP(CSearchResultList::CResultItem)
  34. CFG_ATTRIBUTE( L"Title" , BSTR , m_data.m_bstrTitle ),
  35. CFG_ATTRIBUTE( L"URI" , BSTR , m_data.m_bstrURI ),
  36. CFG_ATTRIBUTE( L"ContentType" , long , m_data.m_lContentType ),
  37. CFG_ATTRIBUTE( L"Rank" , double, m_data.m_dRank ),
  38. CFG_ATTRIBUTE( L"Description" , BSTR , m_data.m_bstrDescription ),
  39. CFG_END_FIELDS_MAP()
  40. CFG_BEGIN_CHILD_MAP(CSearchResultList::CResultItem)
  41. CFG_END_CHILD_MAP()
  42. DEFINE_CFG_OBJECT(CSearchResultList::CResultItem,L"ResultItem")
  43. DEFINE_CONFIG_METHODS__NOCHILD(CSearchResultList::CResultItem)
  44. /////////////////////////////////////////////////////////////////////
  45. CFG_BEGIN_FIELDS_MAP(CSearchResultList)
  46. CFG_ELEMENT(L"PrevQuery", BSTR, m_bstrPrevQuery),
  47. CFG_END_FIELDS_MAP()
  48. CFG_BEGIN_CHILD_MAP(CSearchResultList)
  49. CFG_CHILD(CSearchResultList::CSearchItem)
  50. CFG_CHILD(CSearchResultList::CResultItem)
  51. CFG_END_CHILD_MAP()
  52. DEFINE_CFG_OBJECT(CSearchResultList, L"ResultList")
  53. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(CSearchResultList,tag,defSubType)
  54. if(tag == _cfg_table_tags[0])
  55. {
  56. defSubType = &(*(m_lstSearchItem.insert( m_lstSearchItem.end() )));
  57. return S_OK;
  58. }
  59. if(tag == _cfg_table_tags[1])
  60. {
  61. defSubType = &(*(m_lstResult.insert( m_lstResult.end() )));
  62. return S_OK;
  63. }
  64. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(CSearchResultList,xdn)
  65. hr = MPC::Config::SaveList( m_lstSearchItem, xdn );
  66. hr = MPC::Config::SaveList( m_lstResult, xdn );
  67. DEFINE_CONFIG_METHODS_END(CSearchResultList)
  68. /////////////////////////////////////////////////////////////////////
  69. /////////////////////////////////////////////////////////////////////
  70. // Commenting out MPC:: is a workaround for a compiler bug.
  71. CSearchResultList::CSearchResultList() : /*MPC::*/NamedMutex( g_wszMutexName )
  72. {
  73. }
  74. CSearchResultList::~CSearchResultList()
  75. {
  76. }
  77. /************
  78. Method - CSearchResultList::LoadResults(IStream* pStream)
  79. Description - This method loads the XML file (passed thro the IStream pointer) into a list and sets
  80. the iterator of the list to the first element in the list.
  81. ************/
  82. HRESULT CSearchResultList::LoadResults( /*[in]*/IStream* pStream )
  83. {
  84. __HCP_FUNC_ENTRY( "CSearchResultList::LoadConfiguration" );
  85. HRESULT hr;
  86. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::LoadStream( this, pStream ));
  87. __MPC_EXIT_IF_METHOD_FAILS(hr, MoveFirst());
  88. hr = S_OK;
  89. __HCP_FUNC_CLEANUP;
  90. __HCP_FUNC_EXIT(hr);
  91. }
  92. HRESULT CSearchResultList::ClearResults()
  93. {
  94. __HCP_FUNC_ENTRY( "CSearchResultList::ClearResult" );
  95. m_lstResult.clear();
  96. return S_OK;
  97. }
  98. /************
  99. Method - CSearchResultList::IsCursorValid(), MoveFirst(), MoveNext()
  100. Description - These methods are used to traverse the list that contains the various XML elements of the
  101. loaded file.
  102. ************/
  103. bool CSearchResultList::IsCursorValid()
  104. {
  105. return (m_itCurrentResult != m_lstResult.end());
  106. }
  107. HRESULT CSearchResultList::MoveFirst()
  108. {
  109. m_itCurrentResult = m_lstResult.begin();
  110. return S_OK;
  111. }
  112. HRESULT CSearchResultList::MoveNext()
  113. {
  114. if(IsCursorValid())
  115. {
  116. m_itCurrentResult++;
  117. }
  118. return S_OK;
  119. }
  120. /************
  121. Method - CSearchResultList::InitializeResultObject(SearchEngine::ResultItem *pRIObj)
  122. Description - This method is called by CNetSW::Results() to initialize a result item object. Initializes
  123. with the current result item.
  124. ************/
  125. HRESULT CSearchResultList::InitializeResultObject( /*[out]*/ SearchEngine::ResultItem* pRIObj )
  126. {
  127. if(IsCursorValid()) pRIObj->Data() = m_itCurrentResult->m_data;
  128. return S_OK;
  129. }
  130. /************
  131. Method - CSearchResultList::SetResultItemIterator(long lIndex)
  132. Description - This method returns sets the iterator to the index passed in. This method is called from
  133. CNetSW::Results() when retrieving results from lStart to lEnd. If index passed in is invalid then returns E_FAIL.
  134. ************/
  135. HRESULT CSearchResultList::SetResultItemIterator( /*[in]*/long lIndex )
  136. {
  137. if((lIndex < 0) || (lIndex > m_lstResult.size())) return E_FAIL;
  138. MoveFirst();
  139. std::advance( m_itCurrentResult, (int)lIndex );
  140. return S_OK;
  141. }
  142. /************
  143. Method - CSearchResultList::GetSearchTerms(MPC::WStringList& strList)
  144. Description - This method returns a list of all the search terms
  145. ************/
  146. HRESULT CSearchResultList::GetSearchTerms( /*[in, out]*/ MPC::WStringList& strList )
  147. {
  148. SearchIter it;
  149. it = m_lstSearchItem.begin();
  150. while(it != m_lstSearchItem.end())
  151. {
  152. strList.insert( strList.end(), it->m_strSearchItem );
  153. it++;
  154. }
  155. return S_OK;
  156. }
  157. /************
  158. Method - CSearchResultList::get_PrevQuery()
  159. Description - This method returns the value of the attribute PREV_QUERY - currently this is used
  160. only the PSS search engine to send back the processed query. Used for "Search within results".
  161. ************/
  162. CComBSTR& CSearchResultList::PrevQuery()
  163. {
  164. return m_bstrPrevQuery;
  165. }