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.

263 lines
7.2 KiB

  1. /******************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. PCHSEWrap.cpp
  5. Abstract:
  6. Implementation of SearchEngine::WrapperKeyword
  7. Revision History:
  8. Davide Massarenti (dmassare) 06/01/2001
  9. created
  10. ******************************************************************************/
  11. #include "stdafx.h"
  12. SearchEngine::WrapperKeyword::WrapperKeyword()
  13. {
  14. m_Results = NULL; // CPCHQueryResultCollection* m_Results;
  15. // CComVariant m_vKeywords;
  16. MPC::LocalizeString( IDS_HELPSVC_SEMGR_OWNER , m_bstrOwner , /*fMUI*/true );
  17. MPC::LocalizeString( IDS_HELPSVC_SEMGR_KW_NAME, m_bstrName , /*fMUI*/true );
  18. MPC::LocalizeString( IDS_HELPSVC_SEMGR_KW_DESC, m_bstrDescription, /*fMUI*/true );
  19. m_bstrHelpURL = L"hcp://system/blurbs/keywordhelp.htm";
  20. m_bstrID = L"9488F2E9-47AF-46da-AE4A-86372DEBD56C";
  21. }
  22. SearchEngine::WrapperKeyword::~WrapperKeyword()
  23. {
  24. Thread_Wait();
  25. MPC::Release( m_Results );
  26. }
  27. HRESULT SearchEngine::WrapperKeyword::GetParamDefinition( /*[out]*/ const ParamItem_Definition*& lst, /*[out]*/ int& len )
  28. {
  29. static const ParamItem_Definition c_lst[] =
  30. {
  31. { PARAM_BSTR, VARIANT_FALSE, VARIANT_FALSE, L"SUBSITE" , 0, L"Name of subsite to search", NULL },
  32. { PARAM_BOOL, VARIANT_FALSE, VARIANT_FALSE, L"UI_BULLET", 0, L"UI_BULLET" , L"true" },
  33. };
  34. lst = c_lst;
  35. len = ARRAYSIZE(c_lst);
  36. return S_OK;
  37. }
  38. ////////////////////////////////////////////////////////////////////////////////
  39. STDMETHODIMP SearchEngine::WrapperKeyword::Result( /*[in]*/ long lStart, /*[in]*/ long lEnd, /*[out,retval]*/ IPCHCollection* *ppC )
  40. {
  41. __HCP_FUNC_ENTRY( "SearchEngine::WrapperKeyword::Result" );
  42. HRESULT hr;
  43. MPC::SmartLock<_ThreadModel> lock( this );
  44. CComPtr<CPCHCollection> pColl;
  45. __MPC_PARAMCHECK_BEGIN(hr)
  46. __MPC_PARAMCHECK_POINTER_AND_SET(ppC,NULL);
  47. __MPC_PARAMCHECK_END();
  48. //
  49. // Create the Enumerator and fill it with jobs.
  50. //
  51. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pColl ));
  52. //
  53. // If there are results
  54. //
  55. if(m_Results && m_bEnabled)
  56. {
  57. long lSize = m_Results->Size();
  58. long lPos;
  59. //
  60. // Loop thru all results to generate Enumerator
  61. //
  62. for(lPos=0; lPos<lSize; lPos++)
  63. {
  64. //
  65. // Check if they are between start and end
  66. //
  67. if(lPos >= lStart && lPos < lEnd)
  68. {
  69. CComPtr<CPCHQueryResult> obj;
  70. if(SUCCEEDED(m_Results->GetItem( lPos, &obj )) && obj)
  71. {
  72. CComPtr<SearchEngine::ResultItem> pRIObj;
  73. //
  74. // Create the item to be inserted into the list
  75. //
  76. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pRIObj ));
  77. {
  78. ResultItem_Data& dataDst = pRIObj->Data();
  79. const CPCHQueryResult::Payload& dataSrc = obj->GetData();
  80. dataDst.m_bstrTitle = dataSrc.m_bstrTitle;
  81. dataDst.m_bstrURI = dataSrc.m_bstrTopicURL;
  82. dataDst.m_bstrDescription = dataSrc.m_bstrDescription;
  83. dataDst.m_lContentType = dataSrc.m_lType;
  84. dataDst.m_dRank = -1.0;
  85. }
  86. //
  87. // Add to enumerator
  88. //
  89. __MPC_EXIT_IF_METHOD_FAILS(hr, pColl->AddItem( pRIObj ));
  90. }
  91. }
  92. }
  93. }
  94. __MPC_EXIT_IF_METHOD_FAILS(hr, pColl.QueryInterface( ppC ));
  95. hr = S_OK;
  96. __MPC_FUNC_CLEANUP;
  97. __MPC_FUNC_EXIT(hr);
  98. }
  99. STDMETHODIMP SearchEngine::WrapperKeyword::get_SearchTerms( /*[out, retval]*/ VARIANT *pVal )
  100. {
  101. MPC::SmartLock<_ThreadModel> lock( this );
  102. return ::VariantCopy( pVal, &m_vKeywords );
  103. }
  104. /////////////////////////////////////////////////////////////////////////////
  105. // SearchEngine::WrapperKeyword : IPCHSEWrapperInternal
  106. STDMETHODIMP SearchEngine::WrapperKeyword::AbortQuery()
  107. {
  108. //
  109. // Abort any threads still running
  110. //
  111. Thread_Abort();
  112. return S_OK;
  113. }
  114. STDMETHODIMP SearchEngine::WrapperKeyword::ExecAsyncQuery()
  115. {
  116. __HCP_FUNC_ENTRY( "SearchEngine::WrapperKeyword::ExecAsyncQuery" );
  117. HRESULT hr;
  118. //
  119. // Create a thread to execute the query
  120. //
  121. __MPC_EXIT_IF_METHOD_FAILS(hr, Thread_Start( this, ExecQuery, NULL ));
  122. hr = S_OK;
  123. __MPC_FUNC_CLEANUP;
  124. __MPC_FUNC_EXIT(hr);
  125. }
  126. ////////////////////////////////////////////////////////////////////////////////
  127. HRESULT SearchEngine::WrapperKeyword::ExecQuery()
  128. {
  129. __HCP_FUNC_ENTRY( "SearchEngine::WrapperKeyword::ExecQuery" );
  130. HRESULT hr;
  131. MPC::SmartLock<_ThreadModel> lock( this );
  132. if(m_bEnabled)
  133. {
  134. CComBSTR bstrSubSite;
  135. MPC::WStringList lst;
  136. if(m_bstrQueryString.Length() == 0)
  137. {
  138. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_INVALID_DATA);
  139. }
  140. //
  141. // If previous results exist, release it
  142. //
  143. MPC::Release( m_Results );
  144. //
  145. // Create a new collection
  146. //
  147. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &m_Results ));
  148. //
  149. // Check if search in subsite
  150. //
  151. {
  152. VARIANT* v = GetParamInternal( L"SUBSITE" );
  153. if(v && v->vt == VT_BSTR) bstrSubSite = v->bstrVal;
  154. }
  155. //
  156. // Execute the query
  157. //
  158. {
  159. Taxonomy::Settings ts( m_ths );
  160. __MPC_EXIT_IF_METHOD_FAILS(hr, ts.KeywordSearch( m_bstrQueryString, bstrSubSite, m_Results, &lst ));
  161. }
  162. //
  163. // Sort, first by Priority, then by Content Type.
  164. //
  165. __MPC_EXIT_IF_METHOD_FAILS(hr, m_Results->Sort( CPCHQueryResultCollection::SORT_BYPRIORITY , m_lNumResult ));
  166. __MPC_EXIT_IF_METHOD_FAILS(hr, m_Results->Sort( CPCHQueryResultCollection::SORT_BYCONTENTTYPE ));
  167. //
  168. // Get the list of keywords.
  169. //
  170. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::ConvertListToSafeArray( lst, m_vKeywords, VT_VARIANT ));
  171. }
  172. hr = S_OK;
  173. __MPC_FUNC_CLEANUP;
  174. Thread_Abort();
  175. //
  176. // Call the SearchManager's OnComplete
  177. //
  178. (void)m_pSEMgr->WrapperComplete( hr, this );
  179. __MPC_FUNC_EXIT(hr);
  180. }
  181. ////////////////////////////////////////////////////////////////////////////////
  182. HRESULT SearchEngine::WrapperItem__Create_Keyword( /*[out]*/ CComPtr<IPCHSEWrapperInternal>& pVal )
  183. {
  184. __HCP_FUNC_ENTRY( "SearchEngine::WrapperKeywordperItem__Create_Keyword" );
  185. HRESULT hr;
  186. CComPtr<SearchEngine::WrapperKeyword> pKW;
  187. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pKW ));
  188. pVal = pKW;
  189. hr = S_OK;
  190. __HCP_FUNC_CLEANUP;
  191. __HCP_FUNC_EXIT(hr);
  192. }