asp-classic – 需要用经典ASP(VB)在Server 2012上替换MS索引服务

我刚刚将一个网站从Server 2003迁移到Server 2012,并且MS Indexing服务不可用.

在进行一些研究时,我发现MS Search Service是“替代品”,因此,我将它安装在Server 2012上.除此之外,我还没有找到启用哪些ASP-Classic(VB)代码新的搜索服务可以像索引服务那样对我的文档进行编目.

MS Search Service是否具有编制和搜索文档的能力和灵活性,并以与MS Indexing Service相同的方式返回结果?

下面是当前调用MS索引服务的代码示例(在Windows 2003服务器上):

<%
Dim strQuery   ' The text of our query
Dim objQuery   ' The index server query object
Dim rstResults ' A recordset of results returned from I.S.
Dim objField   ' Field object for loop
Dim objUtility

' Retreive the query from the querystring
strQuery = Request.QueryString("CiRestriction")
if strQuery <> "" then
    if Request.QueryString("ExactPhrase") = "Yes" then
    strQuery = """" & strQuery & """"
    end if
end if

' If the query isn't blank them proceed
If strQuery <> "" Then
    ' Create our index server object
    Set objQuery = Server.CreateObject("IXSSO.Query")

    ' Set its properties

        objQuery.Catalog    = "Test_Docs"  ' Catalog to query
        objQuery.MaxRecords = 75           ' Max # of records to return
        objQuery.SortBy     = "Rank[d], size"
        objQuery.Columns    = "Characterization, DocTitle, Directory, Filename, Path, Rank, Size, Vpath, Write"

        ' Build our Query: Hide admin page and FPSE pages
        'strQuery = "(" & strQuery & ")" _
        '   & " AND NOT #filename = *admin*" _
        '   & " AND NOT #path *\_vti_*"

        ' Uncomment to only look for files modified last 5 days
        'strQuery = strQuery & " AND @write > -5d"

    ' To set more complex scopes we use the utility object.
    ' You can call AddScopeToQuery as many times as you need to.
    ' Shallow includes just files in that folder.  Deep includes
    ' subfolders as well.
    '

    Set objUtility = Server.CreateObject("IXSSO.Util")
    objUtility.AddScopeToQuery objQuery, "d:\test_shares\test_docs", "deep"
    objQuery.Query = strQuery  ' Query text

    Set rstResults = objQuery.CreateRecordset("nonsequential") ' Get a recordset of our results back from Index Server

    ' Check for no records
    If rstResults.EOF Then
        Response.Write "Sorry. No results found."
    Else
        ' Print out # of results
        Response.Write "<p><strong>"
        Response.Write rstResults.RecordCount
        Response.Write "</strong> results found:</p>"

        ' Loop through results      
        Do While Not rstResults.EOF
            ' Loop through Fields
            ' Pretty is as pretty does... good enough:
            %>
            <%KSize=formatnumber(rstResults.Fields("size"))
            KSize= round(KSize/1024,0)%>
            <p>
            <%'test below using PoorMansIsNull function%>
            <% If PoorMansIsNull(rstResults.Fields("DocTitle")) Or rstResults.Fields("DocTitle")="" Then %>

                <a href="/ams/test_docs<%= PathToVpath(rstResults.Fields("path")) %>"  target="_blank"><%= PathToVpath(rstResults.Fields("filename")) %></a>
               <% Else %>
                <a href="/ams/test_docs<%= PathToVpath(rstResults.Fields("path")) %>" target="_blank"><font size="3"><%= rstResults.Fields("DocTitle") %></font></a>
                <% End If %>

                <br><%= rstResults.Fields("Characterization") %><br>

            <font color="#009900"><%= PathToVpath(rstResults.Fields("path")) %> - <%= KSize %>k<br /></font>
            </p>
            <%

            ' Move to next result
            rstResults.MoveNext
        Loop

        rstResults.MoveFirst
        Response.Write "<pre>"
        'Response.Write rstResults.GetString()
        Response.Write "</pre>"
    End If

    ' Kill our recordset object 
    Set rstResults = Nothing
    Set objUtility = Nothing
    Set objQuery = Nothing
End If
%>

</body>
</html>
<%
Function PathToVpath(strPath)
    Const strWebRoot = "d:\test_shares\test_docs\"

    Dim strTemp

    strTemp = strPath

    strTemp = Replace(strTemp, strWebRoot, "\")
    strTemp = Replace(strTemp, "\", "/")

    PathToVpath = strTemp
End Function
%>

并且,结果将按文档列出(文档名称,摘录自文档文本,标题,大小),如下图所示:

感谢任何线索和/或替代方案.

最佳答案 这个例子实际上是不正确的.这是行不通的.以下代码:

objRecordSet.Open "SELECT Top 20 " & _
 "System.ItemPathDisplay " & _
 ",System.ItemName " & _
 ",System.Size " & _
 "FROM SYSTEMINDEX", objConnection & _
 "WHERE SCOPE='file:E:\MANIF\DAAP\AC'"

应该在查询结尾处真正使用连接对象.花了几个小时想知道为什么WHERE子句不起作用.

objRecordSet.Open "SELECT Top 20 " & _
 "System.ItemPathDisplay " & _
 ",System.ItemName " & _
 ",System.Size " & _
 "FROM SYSTEMINDEX " & _
 "WHERE SCOPE='file:E:\MANIF\DAAP\AC'", objConnection

这应该有助于所有遇到同样困难的人.

    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞