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.

211 lines
5.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: Parse.cxx
  7. //
  8. // Contents: Converts restrictions into expressions
  9. //
  10. // Functions: Parse
  11. //
  12. // History: 15-Oct-91 KyleP Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <parse.hxx>
  18. #include <fa.hxx>
  19. #include "notxpr.hxx"
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Function: Parse, public
  23. //
  24. // Synopsis: Convert a restriction into an expression
  25. //
  26. // Arguments: [prst] -- Restriction to convert
  27. // [timeLimit] -- Execution time limit
  28. //
  29. // Returns: A pointer to the expression which will resolve [prst]
  30. //
  31. // History: 15-Oct-91 KyleP Created.
  32. // 27-Nov-93 KyleP Added RTNot
  33. //
  34. //----------------------------------------------------------------------------
  35. CXpr * Parse( CRestriction const * prst, CTimeLimit& timeLimit )
  36. {
  37. XXpr pxp;
  38. CNodeXpr * pnxpr;
  39. int cres;
  40. switch ( prst->Type() )
  41. {
  42. case RTNot:
  43. {
  44. CNotRestriction * pnRst = (CNotRestriction *)prst;
  45. XXpr pTemp( Parse( pnRst->GetChild(), timeLimit ) );
  46. pxp.Set( new CNotXpr( pTemp.Acquire() ) );
  47. break;
  48. }
  49. case RTAnd:
  50. case RTOr:
  51. {
  52. CNodeRestriction * pnRst = prst->CastToNode();
  53. CXpr::NodeType nt = (prst->Type() == RTAnd) ?
  54. CXpr::NTAnd : CXpr::NTOr;
  55. cres = pnRst->Count();
  56. pnxpr = new CNodeXpr( nt, cres );
  57. pxp.Set( pnxpr );
  58. vqDebugOut(( DEB_ITRACE,
  59. "Parse: %s node, %d restrictions\n",
  60. (prst->Type() == RTAnd) ? "AND" : "OR", cres ));
  61. for ( cres--; cres >= 0; cres-- )
  62. {
  63. pnxpr->AddChild( Parse( pnRst->GetChild(cres), timeLimit ) );
  64. }
  65. break;
  66. }
  67. case RTInternalProp:
  68. {
  69. CInternalPropertyRestriction * pRst =
  70. (CInternalPropertyRestriction *)prst;
  71. #if CIDBG == 1
  72. vqDebugOut(( DEB_ITRACE, "Parse: PROPERTY, prop = %d, op = %ld, value = ",
  73. pRst->Pid(),
  74. pRst->Relation() ));
  75. pRst->Value().DisplayVariant(DEB_ITRACE | DEB_NOCOMPNAME, 0);
  76. vqDebugOut(( DEB_ITRACE | DEB_NOCOMPNAME, "\n" ));
  77. #endif // DBG == 1
  78. if ( pRst->Relation() == PRRE )
  79. pxp.Set( new CRegXpr( pRst, timeLimit ) );
  80. else
  81. {
  82. pxp.Set( new CXprPropertyRelation( pRst->Pid(),
  83. pRst->Relation(),
  84. pRst->Value(),
  85. pRst->AcquireContentHelper() ) );
  86. }
  87. break;
  88. }
  89. default:
  90. vqDebugOut(( DEB_ERROR, "Unhandled expression type %d\n", prst->Type() ));
  91. //Win4Assert( !"Unhandled expression type" );
  92. THROW( CException( QUERY_E_INVALIDRESTRICTION ) );
  93. break;
  94. }
  95. return( pxp.Acquire() );
  96. }
  97. //+-------------------------------------------------------------------------
  98. //
  99. // Function: MoveFullyIndexableNode, public
  100. //
  101. // Effects: Splits out any components of [pnrSource] which are
  102. // *completely* resolved by content index. In practice,
  103. // this is boolean trees of CONTENT nodes.
  104. //
  105. // Arguments: [pnrSource] -- Original restriction
  106. // [pnrFullyResolvable] -- Fully resolvable portions of
  107. // [pnrSource]
  108. //
  109. // Modifies: Nodes may be removed from [pnrSource]
  110. //
  111. // History: 10-Feb-92 KyleP Created
  112. //
  113. //--------------------------------------------------------------------------
  114. void MoveFullyIndexable( CNodeRestriction & pnrSource,
  115. CNodeRestriction & pnrFullyResolvable )
  116. {
  117. for ( int i = pnrSource.Count()-1; i >= 0; i-- )
  118. {
  119. if ( IsFullyIndexable( pnrSource.GetChild(i) ) )
  120. {
  121. unsigned pos;
  122. pnrFullyResolvable.AddChild( pnrSource.RemoveChild(i), pos );
  123. }
  124. }
  125. }
  126. //+-------------------------------------------------------------------------
  127. //
  128. // Function: IsFullyIndexable, public
  129. //
  130. // Synopsis: Determines of node (or tree) is fully resolved by content
  131. // index.
  132. //
  133. // Arguments: [pRst] -- Restriction to test
  134. //
  135. // Returns: TRUE if node is fully indexable
  136. //
  137. // History: 10-Feb-93 KyleP Created
  138. //
  139. //--------------------------------------------------------------------------
  140. BOOL IsFullyIndexable( CRestriction * pRst )
  141. {
  142. switch ( pRst->Type() )
  143. {
  144. case RTContent:
  145. case RTWord:
  146. case RTSynonym:
  147. case RTPhrase:
  148. case RTRange:
  149. case RTProperty:
  150. case RTNone: // null-node from noise word in vector query
  151. return( TRUE );
  152. case RTAnd:
  153. case RTOr:
  154. case RTProximity:
  155. case RTVector:
  156. {
  157. CNodeRestriction * pnRst = pRst->CastToNode();
  158. for( int i = pnRst->Count()-1; i >= 0; i-- )
  159. {
  160. if ( !IsFullyIndexable( pnRst->GetChild(i) ) )
  161. return FALSE;
  162. }
  163. return( TRUE );
  164. }
  165. case RTNot:
  166. {
  167. CNotRestriction * pnRst = (CNotRestriction *)pRst;
  168. return( IsFullyIndexable( pnRst->GetChild() ) );
  169. break;
  170. }
  171. default:
  172. vqDebugOut(( DEB_ITRACE,
  173. "Restriction type %d is not fully indexable\n",
  174. pRst->Type() ));
  175. return FALSE;
  176. }
  177. }