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.

361 lines
12 KiB

  1. VERSION 1.0 CLASS
  2. BEGIN
  3. MultiUse = -1 'True
  4. Persistable = 0 'NotPersistable
  5. DataBindingBehavior = 0 'vbNone
  6. DataSourceBehavior = 0 'vbNone
  7. MTSTransactionMode = 0 'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "HssSimSearch"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. ' ====================================================================================
  15. ' Note: Most Functions in this Class have been copied and adapted from the
  16. ' Windows ME Code Base - Specifically file GenKWQueryResults.cpp
  17. '
  18. ' However, the searcher behaves as whistler in that it does not do Synonyms expansion
  19. '
  20. ' Current Limitations (differences with Whistler):
  21. ' ONLY NLS Queries are processed No Boolean Queries.
  22. '
  23. ' ====================================================================================
  24. Option Explicit
  25. Public Event QueryComplete(ByRef bCancel)
  26. Private m_oDoc As DOMDocument ' 30 ' The main DOM Document
  27. Private m_oList As IXMLDOMNodeList ' Holds the Keyword Query Results
  28. Private m_oASQList As IXMLDOMNodeList ' Holds the results from Auto-stringifiable
  29. ' query.
  30. Private m_oMergedResultsList As IXMLDOMNodeList ' The list that merges AutoStringy and KW Query
  31. ' results.
  32. Private m_oMergedResultsDict As Scripting.Dictionary ' a working dictionary
  33. Private m_oXPq As XPQuery ' XPATH Query Builder
  34. Private m_odStw As Scripting.Dictionary ' Output Stopwords Dictionary
  35. ' returned from XPQuery object
  36. Private m_odSs As Scripting.Dictionary ' Output Stopsigns Dictionary
  37. ' returned from XPQuery object
  38. Private m_strQtpl As String ' String XML Representation of Query Template
  39. Private m_strCanonQ As String ' Canonical Query.
  40. Private m_dblQueryTime As Double ' The time it took the Query to execute
  41. Private m_strInputBatch As String ' Input Batch Pathname
  42. Private m_strTestedHht As String ' Input Batch Pathname
  43. Private m_bQueryIsAutoStringifiable As Boolean ' Flag on when AutoStringy Query.
  44. Private m_strAutoStringifyQuery As String ' This holds the resulting Auto-Stringifed Query.
  45. Private Sub Class_Initialize()
  46. Set m_odStw = New Scripting.Dictionary
  47. Set m_odSs = New Scripting.Dictionary
  48. Set m_oDoc = New DOMDocument ' 30
  49. Set m_oMergedResultsDict = New Scripting.Dictionary
  50. End Sub
  51. Function Init( _
  52. ) As Boolean
  53. Init = False
  54. Init = True
  55. Common_Exit:
  56. End Function
  57. Public Property Get XpathQueryTpl() As String
  58. End Property
  59. Public Property Let XpathQueryTpl(ByVal strPath As String)
  60. End Property
  61. Public Property Get XpathQueryTplXml() As String
  62. XpathQueryTplXml = m_strQtpl
  63. End Property
  64. Public Property Let XpathQueryTplXml(ByVal strXml As String)
  65. m_strQtpl = strXml
  66. End Property
  67. Public Property Get TestBatch() As String
  68. TestBatch = m_strInputBatch
  69. End Property
  70. Public Property Let TestBatch(ByVal strPath As String)
  71. m_strInputBatch = strPath
  72. End Property
  73. Public Property Get TestedHht() As String
  74. TestedHht = m_strTestedHht
  75. End Property
  76. Public Property Let TestedHht(ByVal strPath As String)
  77. m_strTestedHht = strPath
  78. OpenHht m_strTestedHht
  79. End Property
  80. Public Property Get MergedResults() As IXMLDOMNodeList
  81. Set MergedResults = m_oMergedResultsList
  82. End Property
  83. Public Property Get KwQResults() As IXMLDOMNodeList
  84. Set KwQResults = m_oList
  85. End Property
  86. Public Property Get AutoStringyQuery() As String
  87. AutoStringyQuery = m_strAutoStringifyQuery
  88. End Property
  89. Public Property Get AutoStringResults() As IXMLDOMNodeList
  90. Set AutoStringResults = m_oASQList
  91. End Property
  92. Public Property Get QueryIsAutoStringifiable() As Boolean
  93. QueryIsAutoStringifiable = m_bQueryIsAutoStringifiable
  94. End Property
  95. Public Property Get StopSigns() As Scripting.Dictionary
  96. Set StopSigns = m_odSs
  97. End Property
  98. Public Property Get StopWords() As Scripting.Dictionary
  99. Set StopWords = m_odStw
  100. End Property
  101. Public Property Get CanonicalQuery() As String
  102. CanonicalQuery = m_strCanonQ
  103. End Property
  104. Public Property Get QueryTiming() As String
  105. QueryTiming = m_dblQueryTime
  106. End Property
  107. Private Sub OpenHht(ByVal strHht As String)
  108. m_oDoc.async = False
  109. m_oDoc.Load "file:///" & strHht
  110. If (m_oDoc.parseError.errorCode <> 0) Then
  111. MsgBox "Error loading XML: " & vbCrLf & _
  112. m_oDoc.parseError.reason & vbCrLf & _
  113. "In: " & m_oDoc.parseError.srcText
  114. GoTo Common_Exit
  115. End If
  116. Set m_oXPq = New XPQuery
  117. m_oXPq.Init m_strQtpl, m_oDoc
  118. Common_Exit:
  119. End Sub
  120. Sub ProcessQuery(ByVal strQuery As String)
  121. Static bInProcess As Boolean
  122. If (bInProcess) Then GoTo Common_Exit
  123. bInProcess = True
  124. Dim strXPathQuery As String
  125. Dim bKwqError As Boolean, bAsqError As Boolean
  126. Dim contextNode As IXMLDOMNode
  127. Dim dblStart As Double, dblEnd As Double
  128. Dim strASQ As String
  129. dblStart = Timer
  130. ' Build the XPATH Query
  131. strXPathQuery = m_oXPq.GetXPathQuery(m_strQtpl, strQuery, _
  132. out_dictStopWords:=m_odStw, _
  133. out_dictStopSigns:=m_odSs, _
  134. out_strCanonicalQuery:=m_strCanonQ, _
  135. out_strXpathAutoStringifyQuery:=strASQ, _
  136. out_strAutoStringifyQuery:=m_strAutoStringifyQuery _
  137. )
  138. ' Execute the Query using XPATH
  139. ' Set the correct querying syntax to XPATH
  140. m_oDoc.setProperty "SelectionLanguage", "XPath"
  141. m_bQueryIsAutoStringifiable = (Len(strASQ) > 0)
  142. ' == In the Following sections I disable errors because the
  143. ' == Selectnodes statement generates exceptions on problems
  144. If (m_bQueryIsAutoStringifiable) Then
  145. On Error Resume Next
  146. Set m_oASQList = m_oDoc.documentElement.selectNodes(strASQ)
  147. bAsqError = (Err.Number <> 0)
  148. If bAsqError Then Stop
  149. Err.Clear
  150. On Error GoTo 0
  151. Else
  152. Set m_oASQList = Nothing
  153. End If
  154. If (Len(strXPathQuery) > 0) Then
  155. On Error Resume Next
  156. Set m_oList = m_oDoc.documentElement.selectNodes(strXPathQuery)
  157. bKwqError = (Err.Number <> 0)
  158. If bKwqError Then Stop
  159. Err.Clear
  160. On Error GoTo 0
  161. Else
  162. Set m_oList = Nothing
  163. End If
  164. ' === Now we merge the Results list =============
  165. Dim oMergedResults As IXMLDOMDocumentFragment
  166. Set oMergedResults = m_oDoc.createDocumentFragment
  167. Set m_oMergedResultsList = Nothing
  168. m_oMergedResultsDict.RemoveAll
  169. Dim oTaxoE As IXMLDOMNode, strURI As String
  170. If (Not m_oASQList Is Nothing) Then
  171. For Each oTaxoE In m_oASQList
  172. strURI = oTaxoE.Attributes.getNamedItem("URI").Text
  173. If (Not m_oMergedResultsDict.Exists(strURI)) Then
  174. oMergedResults.appendChild oTaxoE.cloneNode(deep:=True)
  175. m_oMergedResultsDict.Add strURI, True
  176. End If
  177. Next
  178. End If
  179. If (Not m_oList Is Nothing) Then
  180. For Each oTaxoE In m_oList
  181. strURI = oTaxoE.Attributes.getNamedItem("URI").Text
  182. If (Not m_oMergedResultsDict.Exists(strURI)) Then
  183. oMergedResults.appendChild oTaxoE.cloneNode(deep:=True)
  184. m_oMergedResultsDict.Add strURI, True
  185. End If
  186. Next
  187. End If
  188. Set m_oMergedResultsList = oMergedResults.childNodes
  189. ' ======== End Merge Results Section =============
  190. dblEnd = Timer
  191. m_dblQueryTime = dblEnd - dblStart
  192. ' BUGBUG: QueryComplete should set a system wide Flage that stops everything.
  193. RaiseEvent QueryComplete(False)
  194. bInProcess = False
  195. Common_Exit:
  196. Exit Sub
  197. End Sub
  198. Sub ProcessBatch()
  199. OpenHht m_strTestedHht
  200. Dim oDomQT As DOMDocument: Set oDomQT = New DOMDocument
  201. oDomQT.async = False
  202. oDomQT.preserveWhiteSpace = False
  203. oDomQT.Load m_strInputBatch
  204. RecordRunData oDomQT
  205. Dim oTestList As IXMLDOMNodeList
  206. Set oTestList = oDomQT.selectNodes("hsc-search-test/test-per-se/hsc-search-target")
  207. Dim oQList As IXMLDOMNodeList, oQ As IXMLDOMNode, oURI As IXMLDOMNode, oTaxoE As IXMLDOMNode
  208. Dim strURI As String
  209. Dim oTest As IXMLDOMNode
  210. Dim lX As Long: lX = 0
  211. Dim lExpectedPos As Long, oExpPos As IXMLDOMNode
  212. Dim bFound As Boolean, bTestPassed As Boolean
  213. Dim oElem As IXMLDOMElement
  214. For Each oTest In oTestList
  215. strURI = oTest.selectSingleNode("expect-uri").childNodes(0).Text
  216. Set oQList = oTest.selectNodes("questions-list/question")
  217. For Each oQ In oQList
  218. ' Me.txtInput = oQ.childNodes(0).Text
  219. ProcessQuery oQ.childNodes(0).Text
  220. bFound = False: bTestPassed = False
  221. For Each oTaxoE In m_oMergedResultsList
  222. lX = lX + 1
  223. If (oTaxoE.Attributes.getNamedItem("URI").nodeValue = strURI) Then
  224. bFound = True
  225. Exit For
  226. End If
  227. Next
  228. Set oExpPos = oQ.selectSingleNode("expected-uri-position")
  229. If (bFound) Then
  230. ' URI was found
  231. lExpectedPos = oExpPos.childNodes(0).Text
  232. If (lX > lExpectedPos) Then
  233. bTestPassed = False
  234. Debug.Print "Did not Match Position Requirements"
  235. Else
  236. bTestPassed = True
  237. Debug.Print "Did match position Requirements"
  238. End If
  239. Else
  240. ' URI was not found
  241. bTestPassed = False
  242. Debug.Print "URI Was not Found"
  243. End If
  244. ' now we write this information back to the Quetion.
  245. Set oElem = oQ.ownerDocument.createElement("passed-test")
  246. oElem.Text = IIf(bTestPassed, "yes", "no")
  247. oQ.insertBefore oElem, oExpPos
  248. Set oElem = oQ.ownerDocument.createElement("detected-uri-position")
  249. If (bTestPassed) Then
  250. oElem.Text = lX
  251. Else
  252. oElem.Text = "n/a"
  253. End If
  254. oQ.appendChild oElem
  255. Next
  256. Next
  257. ' now we copy everything to the new DOM Tree
  258. CreateOutputTree oDomQT
  259. oDomQT.save FilenameNoExt(m_strInputBatch) + "_results." + FileExtension(m_strInputBatch)
  260. End Sub
  261. Sub RecordRunData(ByRef oDomQT As DOMDocument)
  262. Dim oTestInfo As IXMLDOMNode
  263. Set oTestInfo = oDomQT.selectSingleNode("hsc-search-test/test-info")
  264. Dim oElem As IXMLDOMElement
  265. Set oElem = oDomQT.createElement("test-stress-file")
  266. oElem.Text = m_strInputBatch
  267. oTestInfo.appendChild oElem
  268. Set oElem = oDomQT.createElement("tested-hht-file")
  269. oElem.Text = m_strTestedHht ' Me.txtHht
  270. oTestInfo.appendChild oElem
  271. Set oElem = oDomQT.createElement("run-date")
  272. oElem.Text = Date & " - " & Time
  273. oTestInfo.appendChild oElem
  274. End Sub
  275. Sub CreateOutputTree(ByRef oDomQT As DOMDocument)
  276. Dim oNewRoot As IXMLDOMElement
  277. Dim oOldRoot As IXMLDOMNode, oSubNode As IXMLDOMNode
  278. Set oNewRoot = oDomQT.createElement("hsc-search-test-results")
  279. Set oOldRoot = oDomQT.selectSingleNode("hsc-search-test")
  280. For Each oSubNode In oOldRoot.childNodes
  281. oOldRoot.removeChild oSubNode
  282. oNewRoot.appendChild oSubNode
  283. Next
  284. oDomQT.removeChild oOldRoot
  285. oDomQT.appendChild oNewRoot
  286. End Sub