Source code of Windows XP (NT5)
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.

235 lines
6.3 KiB

  1. // Copyright (C) 1996-1997 Microsoft Corporation. All rights reserved.
  2. //
  3. // FTS.H
  4. //
  5. #if _MSC_VER > 1000
  6. #pragma once
  7. #endif
  8. #ifndef __FTS_H__
  9. #define __FTS_H__
  10. #ifndef __SITEMAP_H__
  11. #include "sitemap.h"
  12. #endif
  13. // Shroom header files
  14. //
  15. #include "itquery.h"
  16. #include "itgroup.h"
  17. #include "itcc.h"
  18. #include "itrs.h"
  19. #include "itdb.h"
  20. #include "itww.h"
  21. class CExCollection;
  22. class CExTitle;
  23. class CCombinedFTS;
  24. class CSubSet;
  25. class CUWait;
  26. #define FTS_TITLE_ONLY 0x0001
  27. #define FTS_ENABLE_STEMMING 0x0002
  28. #define FTS_SEARCH_PREVIOUS 0x0004
  29. #define FTS_NO_INDEX MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,100)
  30. #define FTS_NOT_INITIALIZED MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,101)
  31. #define FTS_E_SKIP_TITLE MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,102)
  32. #define FTS_E_SKIP_VOLUME MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,103)
  33. #define FTS_E_SKIP_ALL MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,104)
  34. #define FTS_INVALID_SYNTAX MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,105)
  35. #define FTS_CANCELED MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,106)
  36. #define MAX_HIGHLIGHT_TERMS 128
  37. typedef struct CHM_MapEntry
  38. {
  39. char szChmName[50];
  40. WORD iIndex;
  41. FILETIME versioninfo;
  42. LCID language;
  43. DWORD dwTopicCount;
  44. } CHM_MAP_ENTRY;
  45. DWORD Han2Zen(unsigned char *lpInBuffer, unsigned char *lpOutBuffer, UINT codepage);
  46. WCHAR* PreProcessQuery(WCHAR *pwcQuery, UINT codepage);
  47. BOOL compareOperator(char *pszQuery, char *pszTerm);
  48. int IsJOperator(char *pszQuery);
  49. int FASTCALL CompareIntValues(const void *pval1, const void *pval2);
  50. ERR SearchMessageFunc(DWORD dwFlag, LPVOID pUserData, LPVOID pMessage);
  51. BOOL IsQuery(char *pszQuery);
  52. // FTS Results structure
  53. //
  54. typedef struct _search_result
  55. {
  56. DWORD dwTopicNumber;
  57. DWORD dwRank;
  58. CExTitle *pTitle;
  59. } SEARCH_RESULT;
  60. class CTitleFTS;
  61. //
  62. // Topic numbers in IVQ files will be reduced from 32bit numbers to 22bit numbers.
  63. // The high 10 bits will be used as an CHM ID.
  64. //
  65. // Conversion from DWORD to CHM_ID and Topic Number.
  66. //
  67. #define CHM_ID(exp) (0x000003ff & (exp >> 22))
  68. #define TOPIC_NUM(exp) (0x003fffff & exp)
  69. // Conversion from CHM_ID and Topic Number to DWORD.
  70. //
  71. #define PACKED_TOPICNUM(iTopNum, iChmID) ((iChmID << 22) | iTopNum)
  72. // Title array structure
  73. //
  74. typedef struct _titleArray
  75. {
  76. CExTitle *pExTitle;
  77. CCombinedFTS *pCombinedFTI;
  78. BOOL bSearch;
  79. BOOL bCombinedIndex;
  80. WORD iTitleIndex;
  81. FILETIME versioninfo;
  82. char *pszQueryName;
  83. char *pszIndexName;
  84. char *pszShortName;
  85. LCID language;
  86. DWORD dwTopicCount;
  87. UINT uiVolumeOrder;
  88. BOOL bHasResults;
  89. BOOL bAlreadyQueried;
  90. } TITLE_ENTRY;
  91. // CFullTextSearch class
  92. //
  93. class CFullTextSearch
  94. {
  95. public:
  96. CFullTextSearch(CExCollection *pTitleCollection);
  97. ~CFullTextSearch();
  98. HRESULT SimpleQuery(WCHAR *pszQuery, int *cResultCount, SEARCH_RESULT **);
  99. HRESULT ComplexQuery(WCHAR *pszQuery, DWORD dwFlags, int *cResultCount, SEARCH_RESULT **, CSubSet *pSubSet);
  100. HRESULT AbortQuery();
  101. HRESULT SetProximity(WORD wNear);
  102. HRESULT SetResultCount(LONG cRows);
  103. HRESULT SetOptions(DWORD dwFlag);
  104. void InitTitleArray(void);
  105. BOOL LoadCombinedIndex(DWORD);
  106. CCombinedFTS * GetPreviousInstance(char *pszQueryName);
  107. CExTitle *LookupTitle(CCombinedFTS *, DWORD);
  108. HRESULT AddHLTerm(WCHAR *, int len);
  109. HRESULT CFullTextSearch::AddQueryToTermList(WCHAR *pwsBuffer);
  110. HRESULT TermListRemoveAll(void);
  111. WCHAR * GetHLTermAt(int index);
  112. INT GetHLTermCount(void);
  113. VOID FreeResults(SEARCH_RESULT *);
  114. long ComputeResultCount(IITResultSet *pResultSet);
  115. PCSTR m_pszITSSFile;
  116. BOOL Initialize();
  117. long m_lMaxRowCount;
  118. WORD m_wQueryProximity;
  119. DWORD m_dwQueryFlags;
  120. int m_iLastResultCount;
  121. TITLE_ENTRY *m_pTitleArray;
  122. BOOL m_bMergedChmSetWithCHQ; // When true, we are running a merged chm set that has
  123. // a combined index (NT5 Help).
  124. protected:
  125. LANGID m_SystemLangID;
  126. WCHAR *m_HLTermArray[MAX_HIGHLIGHT_TERMS];
  127. int m_iHLIndex;
  128. BOOL m_bInit;
  129. BOOL m_InitFailed;
  130. BOOL m_SearchActive;
  131. CExCollection *m_pTitleCollection;
  132. BOOL m_bTitleArrayInit;
  133. INT m_TitleArraySize;
  134. };
  135. // CTitleFTS class
  136. //
  137. class CTitleFTS
  138. {
  139. public:
  140. CTitleFTS(PCSTR pwszTitlePath, LCID lcid, CExTitle *);
  141. void ReleaseObjects();
  142. ~CTitleFTS();
  143. HRESULT Query(WCHAR *pszQuery, DWORD dwFlags, IITResultSet **, CFullTextSearch *pFullTextSearch, CUWait *, int);
  144. HRESULT AbortQuery();
  145. IITResultSet * GetResultsSet(void) { return m_pITResultSet; }
  146. HRESULT SetProximity(WORD wNear);
  147. HRESULT SetResultCount(LONG cRows);
  148. HRESULT SetOptions(DWORD dwFlag);
  149. VOID FreeResults(SEARCH_RESULT *);
  150. HRESULT Initialize();
  151. HRESULT UpdateOptions(WORD wNear, LONG cRows);
  152. protected:
  153. UINT m_codepage;
  154. long m_iLastResultCount;
  155. WCHAR *m_pPrevQuery;
  156. BOOL m_bInit;
  157. CExTitle *m_pTitle;
  158. HRESULT m_InitError;
  159. BOOL m_InitFailed;
  160. BOOL m_SearchActive;
  161. DWORD m_dwQueryFlags;
  162. LCID m_lcid;
  163. IITIndex *m_pIndex;
  164. IITQuery *m_pQuery;
  165. IITResultSet *m_pITResultSet;
  166. IITDatabase *m_pITDB;
  167. LANGID m_SystemLangID;
  168. LANGID m_langid;
  169. BOOL m_fDBCS;
  170. WCHAR m_tcTitlePath[MAX_PATH];
  171. long m_lMaxRowCount;
  172. WORD m_wQueryProximity;
  173. inline BOOL Init() { if( !m_bInit ) Initialize(); return m_bInit; }
  174. };
  175. // CCombinedFTS class
  176. //
  177. class CCombinedFTS
  178. {
  179. public:
  180. CCombinedFTS(CExTitle *, LCID lcid, CFullTextSearch *);
  181. ~CCombinedFTS();
  182. HRESULT Query(WCHAR *pszQuery, DWORD dwFlags, IITResultSet **, CFullTextSearch *pFullTextSearch, CUWait *, int);
  183. HRESULT AbortQuery();
  184. IITResultSet * GetResultsSet(void) { return m_pITResultSet; }
  185. VOID FreeResults(SEARCH_RESULT *);
  186. HRESULT Initialize();
  187. HRESULT UpdateOptions(WORD wNear, LONG cRows);
  188. void ReleaseObjects();
  189. protected:
  190. UINT m_codepage;
  191. long m_iLastResultCount;
  192. HRESULT SetProximity(WORD wNear);
  193. HRESULT SetResultCount(LONG cRows);
  194. HRESULT SetOptions(DWORD dwFlag);
  195. CExTitle *m_pTitle;
  196. CFullTextSearch *m_pFullTextSearch;
  197. BOOL m_SearchActive;
  198. DWORD m_dwQueryFlags;
  199. LCID m_lcid;
  200. WCHAR *m_pPrevQuery;
  201. IITIndex *m_pIndex;
  202. IITQuery *m_pQuery;
  203. IITResultSet *m_pITResultSet;
  204. IITDatabase *m_pITDB;
  205. LANGID m_SystemLangID;
  206. LANGID m_langid;
  207. BOOL m_fDBCS;
  208. WCHAR m_tcTitlePath[MAX_PATH];
  209. long m_lMaxRowCount;
  210. WORD m_wQueryProximity;
  211. };
  212. #endif // __FTS_H__