Lotus中定制搜索

          Sub SearchWeb()
           Dim QryDB As NotesDatabase
           Dim vwDBList As NotesView
           Dim sQueryString As String
           Dim sMinRecord,sMaxRecord,sSortMethod,sTemp,sQry,sOldQry,sSymbol As String
           Dim sSearchFuzzy As String
           Dim sUseCache As String
           Dim sServername As String
           Dim sDbName As String
           Dim sViewName As String
           Dim sPage As String
           Dim sCondition As String
           Dim sDBDocID As String
           Dim sFields As String
           Dim vResult() As Variant
           Dim vTemp,vDBDocList As Variant
           Dim i,j,iRecordNumber As Integer
           
           Set session = New NotesSession
           Set db = session.currentdatabase
           Set doc = session.documentcontext
           sQry = doc.Query_String_Decoded(0)
           sOldQry = sQry
           '-------------------------------- 獲取查詢參數(shù) --------------------------------------
           vTemp = Evaluate("@ReplaceSubstring('"+sQry+"';'+';' ')")
           
           sTemp = vTemp(0)
           sQry = sTemp
           
           i = Instr(sTemp,"^")
           sCondition = Mid(sTemp,i+1) '查詢條件
           
           sDBDocID = Left(sTemp,i-1)
           i = Instr(sDBDocID,"&")
           sDBDocID = Mid(sDBDocID,i+1)'查詢視圖參數(shù)
           
           'sSortMethod = Mid(sCondition,Instr(sCondition,"~")+1,1)'排序方式 
           sSearchFuzzy = Mid(sCondition,Instr(sCondition,"!")+1,1)'是否使用模糊查詢
           sUseCache = Mid(sCondition,Instr(sCondition,"$")+1,1)'是否使用Cache
           
           i = Instr(sCondition,"@")
           j = Instr(i+1,sCondition,"@")
           sMinRecord=Val(Mid(sCondition,i+1,j-i-1))'查詢記錄起始數(shù)
           sMaxRecord=Val(Mid(sCondition,j+1))'查詢記錄每頁最大結(jié)果數(shù)
           sCondition = Mid(sCondition,1,i-1)'取得查詢關(guān)鍵字 
           
           vDBDocList = Extract(sDBDocID,",") '獲取查詢視圖參數(shù)的數(shù)組
           
           Call ExtractArray(sCondition) '獲取查詢關(guān)鍵字列表
           iRecordNumber = 0
           sPage = ""
           sSymbol = ""
           If sSearchFuzzy = "1" Then
            sSymbol = "*"
           End If
           '------------------------------------------------------------------------------------
           '---------------------------------- 開始查詢 ----------------------------------------
           Forall x In vDBDocList
            vTemp = Extract(Cstr(x),"!")'拆分查詢參數(shù)(所在服務(wù)器!所在數(shù)據(jù)庫!查詢視圖)
            
            sServerName=vTemp(0)'查詢數(shù)據(jù)庫所在服務(wù)器
            sDbName=vTemp(1)'查詢數(shù)據(jù)庫
            sViewName = vTemp(2)'查詢的視圖名
            
            Set QryDB = New NotesDatabase(sServerName,sDbName)'取得查詢數(shù)據(jù)庫對象
            
            Set view = QryDB.getview(sViewName)'取得查詢數(shù)據(jù)庫視圖
            sQry=""
            sQueryString = ""
            Forall y In sQryKey
             sQry = Replace(y,"""","''")
             sTemp = ""
             '當指定域查詢時
             If doc.Fields(0) <> "" Then
              Forall z In doc.Fields
               If sTemp = "" Then
                sTemp = "FIELD "+z+{ contains "}+sSymbol+sQry+sSymbol+{"}
               Else
                sTemp = sTemp + " AND FIELD "+z+{ contains "}+sSymbol+sQry+sSymbol+{"}
               End If
              End Forall
              
              If sQueryString = "" Then
               sQueryString = "(" + sTemp +")"
              Else
               sQueryString = sQueryString + " OR (" + sTemp +")"
              End If
             Else'未指定域
              If sQueryString = "" Then
               sQueryString = sQry
              Else
               sQueryString = sQueryString + " AND " + sQry
              End If
             End If
            End Forall
            j = view.FTSearch( sQueryString, Cint(sMaxRecord))'開始查詢
            '將結(jié)果形成XML數(shù)據(jù)
            If j>0 Then
             For i = 1 To j
              iRecordNumber = iRecordNumber + 1
              Set qrydoc = view.getnthdocument(i)
              sPage = sPage + {<row url="javascript:opendoc('/}+QryDB.Replicaid+{/0/}+qrydoc.Universalid+{?opendocument')">}
              sPage = sPage + {<number>}+Cstr(iRecordNumber)+{</number>}
              sPage = sPage + {<title>}+qrydoc.ColumnValues(0)+{</title>}
              sPage = sPage + {<category>}+doc.Name(0)+{</category>}
              sPage = sPage + {<score>}+Cstr(qrydoc.FTSearchScore)+{%</score>}
              sPage = sPage + {</row>}
             Next
            End If
            Call view.clear
           End Forall
           '------------------------------------------------------------------------------------
           '---------------------------------- 輸出結(jié)果 ----------------------------------------
           Print {Content-type: text/xml}
           Print {<?xml version='1.0' encoding="utf-8" ?>}
           Print {<view name="查詢結(jié)果" id="vgosearchresult.xml">}
           Print {<header>}
           Print { <number>序號</number>}
           Print { <title>標題</title>}
           Print { <category>位置</category>}
           Print { <score>匹配度</score>}
           Print {</header>}
           Print {<action/>}
           Print {<rows>}
           Print sPage
           Print {</rows>}
           Print {</view>}
           '------------------------------------------------------------------------------------
          End Sub

          posted on 2010-04-09 09:21 明高 閱讀(142) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2010年4月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 吴忠市| 高台县| 沙河市| 晋宁县| 当阳市| 泊头市| 曲松县| 赤城县| 沂水县| 罗山县| 抚顺市| 南城县| 乐昌市| 陆良县| 娱乐| 阿荣旗| 海淀区| 南通市| 平谷区| 海口市| 庆云县| 辉南县| 班玛县| 香格里拉县| 淄博市| 朔州市| 临沧市| 霍邱县| 岐山县| 福清市| 文山县| 卓资县| 湖北省| 论坛| 龙南县| 苍溪县| 故城县| 桦南县| 新乡县| 珠海市| 姚安县|