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.

136 lines
4.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998
  5. //
  6. // File: qsplit.cxx
  7. //
  8. // Contents: Function to parse and split query into indexable/non-indexable
  9. // parts
  10. //
  11. // History: 26-Sep-94 SitaramR Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #include <pch.cxx>
  15. #pragma hdrstop
  16. #include <xpr.hxx>
  17. #include <cci.hxx>
  18. #include <parse.hxx>
  19. #include <pidmap.hxx>
  20. #include <qparse.hxx>
  21. #include <lang.hxx>
  22. #include <split.hxx>
  23. #include <qsplit.hxx>
  24. #include <qoptimiz.hxx>
  25. #include <qiterate.hxx>
  26. //+---------------------------------------------------------------------------
  27. //
  28. // Function: ParseAndSplitQuery
  29. //
  30. // Synopsis: Parses the restriction and then splits it into indexable and
  31. // non-indexable parts. The non-indexable part is thrown away.
  32. //
  33. // Arguments: [pRestriction] -- Input restriction
  34. // [PidMap ] -- Pid mapper to be filled with mappings
  35. // [xOutRst] -- The indexable part of the restriction will
  36. // be put in this.
  37. // [langList] -- Language list (for word breakers)
  38. //
  39. // Returns: SCODE of the operation.
  40. //
  41. // History: 7-23-96 srikants Adapted from SitaramR's code.
  42. //
  43. // Notes: A multi-part query experssion is split into individual components
  44. // and from each component, only the indexable portion is taken.
  45. // All the indexable components are composed by using an OR
  46. // node.
  47. //
  48. //----------------------------------------------------------------------------
  49. SCODE ParseAndSplitQuery( CRestriction * pRestriction,
  50. CPidMapper & Pidmap,
  51. XRestriction& xOutRst,
  52. CLangList & langList )
  53. {
  54. SCODE sc = STATUS_SUCCESS;
  55. TRY
  56. {
  57. if ( 0 != pRestriction )
  58. {
  59. BOOL fCIRequiredGlobal;
  60. CTimeLimit timeLimit( ULONG_MAX, 0 ); // Must precede xXpr (CDFA has reference)
  61. XRestriction xRstParsed;
  62. XXpr xXpr;
  63. XRestriction xFullyResolvableRst;
  64. CQParse qparse( Pidmap, langList ); // Maps name to pid
  65. xRstParsed.Set( qparse.Parse( pRestriction ) );
  66. CQueryRstIterator qRstIterator( 0,
  67. xRstParsed,
  68. timeLimit,
  69. fCIRequiredGlobal,
  70. TRUE, // No Timeout,
  71. FALSE // Don't validate catalog
  72. );
  73. qRstIterator.GetFirstComponent( xFullyResolvableRst, xXpr );
  74. if ( qRstIterator.AtEnd() )
  75. {
  76. xOutRst.Set( xFullyResolvableRst.Acquire() );
  77. }
  78. else
  79. {
  80. XNodeRestriction xRstTemp( new CNodeRestriction( RTOr, 2 ) );
  81. if ( 0 != xFullyResolvableRst.GetPointer() )
  82. xRstTemp->AddChild( xFullyResolvableRst.Acquire() );
  83. delete xXpr.Acquire();
  84. while ( !qRstIterator.AtEnd() )
  85. {
  86. qRstIterator.GetNextComponent( xFullyResolvableRst, xXpr );
  87. if ( 0 != xFullyResolvableRst.GetPointer() )
  88. xRstTemp->AddChild( xFullyResolvableRst.Acquire() );
  89. delete xXpr.Acquire();
  90. }
  91. switch ( xRstTemp->Count() )
  92. {
  93. case 0:
  94. break;
  95. case 1:
  96. xOutRst.Set( xRstTemp->RemoveChild( 0 ) );
  97. break;
  98. default:
  99. xOutRst.Set( xRstTemp.Acquire() );
  100. break;
  101. }
  102. }
  103. }
  104. else
  105. {
  106. sc = QUERY_E_INVALIDRESTRICTION;
  107. }
  108. }
  109. CATCH( CException, e )
  110. {
  111. sc = e.GetErrorCode();
  112. }
  113. END_CATCH
  114. return sc;
  115. }