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
 '-------------------------------- 获取查询参数 --------------------------------------
 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)'查询视图参数
 
 '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))'查询记录起始数
 sMaxRecord=Val(Mid(sCondition,j+1))'查询记录每页最大结果数
 sCondition = Mid(sCondition,1,i-1)'取得查询关键字 
 
 vDBDocList = Extract(sDBDocID,",") '获取查询视图参数的数组
 
 Call ExtractArray(sCondition) '获取查询关键字列表
 iRecordNumber = 0
 sPage = ""
 sSymbol = ""
 If sSearchFuzzy = "1" Then
  sSymbol = "*"
 End If
 '------------------------------------------------------------------------------------
 '---------------------------------- 开始查询 ----------------------------------------
 Forall x In vDBDocList
  vTemp = Extract(Cstr(x),"!")'拆分查询参数(所在服务器!所在数据库!查询视图)
  
  sServerName=vTemp(0)'查询数据库所在服务器
  sDbName=vTemp(1)'查询数据库
  sViewName = vTemp(2)'查询的视图名
  
  Set QryDB = New NotesDatabase(sServerName,sDbName)'取得查询数据库对象
  
  Set view = QryDB.getview(sViewName)'取得查询数据库视图
  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))'开始查询
  '将结果形成XML数据
  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
 '------------------------------------------------------------------------------------
 '---------------------------------- 输出结果 ----------------------------------------
 Print {Content-type: text/xml}
 Print {<?xml version='1.0' encoding="utf-8" ?>}
 Print {<view name="查询结果" 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 明高 阅读(129) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2010年4月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

导航

统计

常用链接

留言簿

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜