Sub Initialize
'设置页面属性
Print <html>
Print <head>
Print <meta http-equiv='Content-Type' content='text/html;charset=gb2312'>
Print <title>
Print 数据库搜索结果
Print </title>
Print <style type=text/css>
Print <!-- a{font-size:9pt;text-decoration:none;color:#000000} --></style>
Print </head>
'设置HTML页面的背景颜色:
Print <body text='#000000' bgcolor='#f7f7f7'>
Print <form name='sear'>
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim collection As NotesDocumentCollection
Dim ser As String
Dim dbstr As String
Dim searchstr As String
Dim MatchDoc As NotesDocument
Set db = session.currentdatabase
Set doc = session.DocumentContext
If doc.hasItem(Query) Then
If doc.Query(0) = Then
Goto EmptyQuery
Else
searchstr = doc.Query(0)
End If
Else
searchstr = Strleft(Strright(Strright((doc.Query_String_Decoded(0)),&),=),&) End If
On Error Goto BadQuery
Messagebox The searching string is: & searchstr
'################################################## ##############################################
'判断是否本数据库已经全文索引,如果没有则建立之。暂时先强制执行全文索引,到使用时再加上条件。
'If Not(db.IsFTindexed) Then
Call db.UpdateFTIndex(False)
'End If
'######################################################### #######################################
'建立搜索字符串:用域的值去形成,不可以选择搜索条件,自动为模糊搜索(16384)。
Set collection = db.ftsearch(searchstr,0,32,16384)
On Error Goto 0
Messagebox Documents found: + Str$(collection.count)
'##################################### ###########################################################
'打印文档输出
'用表格方式显示搜索结果(开始) ////////////////////////////////////////////////////////////////
&n bsp;Print <center><table border='1' width='800' bordercolor='#E1E1E1' cellspacing='0' cellpadding='5' valign='MIDDLE'>
'设置表头
Print <tr><td width='100' bgcolor='#E1E1E1'><b>
Print <font size='3'>搜索数据库 </font></b></td><td bgcolor='#E1E1E1'><font size='3'><b>
Print db.title
Print </b></td></tr></table>
Print <br>
Print <table border='1' width='800' cellspacing='0' bordercolor='#E1E1E1' cellspacing='0' cellpadding='5' valign='MIDDLE'>
Print <tr>
Print <td width='800' align='center' bgcolor='#E1E1E1' colspan='4'>
Print <p align='left'><b><font size=2> 共搜索到 & Str$(collection.count) & 个文档。 </font></b></td>
Print </tr>
Print <center>
Print <tr>
Print <td width='40' align='center' bgcolor='#EFEFEF'> </td>
Print <td width='600' align='center' bgcolor='#EFEFEF'><b><font size=2>标 题 </font></b></td>
Print <td width='200' align='center' bgcolor='#EFEFEF'><b><font size=2>作 者</font></b></td>
Print <td width='300' align='center' bgc olor='#EFEFEF'><b><font size=2>创建时间 </font></b></td>
Print </tr>
'/////////////////////////////////////////
& nbsp;'取得文档并打印出来
'声明要显示字段值的变量,需要的话可以进行修改。
Dim Item As NotesItem
Dim i As Integer
Dim startPosition As Integer
Dim endPosition As Integer
Dim tempstr As String
'设置每页显示的行数
ResultPerPage = 10
If doc.Query_String_Decoded(0) = Then
startPosition = 1
Else
'计算 startPosition的值
tempstr = Strright(Strright((doc.Query_String_Decoded(0)),=),=)
startPo sition = Int(tempstr)
End If
endPosition = startPosition + ResultPerPage - 1
Messagebox 开始行数: & startPosition
Messagebox 结束行数: & endPosition
dbstr = db.filename
ser = Strright(Strleft(db.server,/),=)
If endPosition > collection.count Then
endPosition = collection.count
End If
For i = startPosition To endPosition
Set MatchDoc = collection.getnthdocument(i)
'这里的Item等字段,可根据自己的需要来修改。其中的任何一个都能作为链接来显示。
Set item = MatchDoc.GetFirstItem(CarType)
If(item Is Nothing) Then
Set item = MatchDoc.GetFirstItem(CarType)
End If
'此处向下打印结果,用表格的形式显示,在最后(此循环外)加分页显示功能。
If Not(item Is Nothing) Then
Print <tr>
Print <td align='center' width='40' bgcolor='F7F7F7'><img src='left.gif'></td>
Print <td width='600' bgcolor='#F7F7F7'><font size='2'>
Print <a href=http:// &ser & / & dbstr & /$all/ & MatchDoc.UniversalID & ?OpenDocument>
Print item.Text
Print </a></font></td>
End If
Print <td align='center' width='200' bgcolor='#F7F7F7'><font size='2'>
'##############################
'作者的定义还要变,因为不在names.nsf中注册,只是保存了一个用户名而已
Forall aAuthor In MatchDoc.Authors
Print Strright(Strleft(aAuthor,/),=)
Goto OneUser 'Goal is to display the origin Author: the first one
End Forall
OneUser:
Print </font></td>
createDate = MatchDoc.Created
Print <td align='center' width='300' bgcolor='#F7F7F7'><font size='2'>
Print createDate
Print </font></td>
Print </tr>
Next
'////// ///////////////////////////////////
'计算总页数、当前页,并打印其它页的链接。
Dim totaldocs,totalpages As Integer
Dim loopk As Integer
Dim ytm As Integer
totaldocs = collection.count
If ((totaldocs Mod ResultPerPage) = 0) Then
totalpages = Cint(totaldocs/ResultPerPage)
Else
totalpages = Cint(totaldocsResultPerPage) + 1
End If
Print <tr><td align='center' bgcolor='#E1E1E1' colspan='4'><font size='2'>
Print 分页:共有( & totalpages & )页
'############################################ ###################################
'打印分页链接
For loopk = 1 To totalpages
ytm = (loopk-1)*ResultPerPage+1
Print <a href='http:// & ser & / & dbstr & /NewSearchAgent?OpenAgent&searchstring= & searchstr & &start= & ytm & '>
Print 第 & loopk & 页</a>
Next
Print <tr><td align='center' bgcolor='#F7F7F7' colspan='4'><font size='2'>
Print 【
Print <a href='SearchForm?openform'>继续搜索</a> '这里需要修改成当前库的定制搜索表单名称
Print 】</tr>
Print </center></table>
Out:
Print </form></body>
Print </html>
Exit Sub
EmptyQuery:
Print <br><br><br>
Print <center><table border=1 width=400 bordercolor='#E1E1E1' cellspacing=0 cellpadding=5 valign=MIDDLE>
Print <tr><td bgcolor='#E1E1E1'><font size='3'><b>  错误 </b></font></td></tr>
Print <tr><td align='center' bgcolor='#EFEFEF'><font size='3'><b>搜索字符串不能为空。 </b></font></td>
Print <tr><td align='center' bgcolor='#F7F7F7'><font size='2'>
Print 【
Print <a href='javascript:history.back()'>
Print 返回</a>
Print 】
Print </font></td></tr></table></center>
Resu me Out
BadQuery:
Print <br><br>
Print <center><table border=1 width=400 bordercolor='#E1E1E1' cellspacing=0 cellpadding=5 valign=MIDDLE>
Print <tr><td bgcolor='#E1E1E1'><font size='3'><b>  错误 </b></font></td></tr>
Print <tr><td bgcolor='#EFEFEF'><font size='3'><b>    输入了非法字符串: </b></font></td>
Print <tr><td bgcolor='#07BFF8'><font size='3'>      
Pri nt doc.Query(0)
Print </font></td></tr>
Print <tr><td align='center' bgcolor='#F7F7F7'><font size='2'>
Print 【
Print <a href='SearchForm?openform'>继续 </a> '这里需要修改成当前库的定制搜索表单名称
Print 】  
Print 【
Print <a href='javascript:history.back()'>
Print 返回 </a>
Print 】
Print </font></td></tr></table></center>
&nbs p;Resume Out
Print </form></body></html>
End Sub
我看了你的搜索分页的源代码,我试着做了一个搜索分页的例子。在制作的过程中我遇到一个问题,那就是doc.Query_String_Decoded(0),你那个Query_String_Decoded应该是搜索表单中的一个域吧,他具体存的是表单的什么值呢。麻烦你告诉我,谢谢了!!
在域里选择default value的值,里面写Query_String_Decoded
注意是显示时计算!
我现在还是不太明白,你们说的是Query_String_Decoded是CGI变量,是一个系统变量么??那应该是存的是query的值,可是我具体还是不知道
If doc.Query_String_Decoded(0) = Then
startPosition = 1
Else
'计算 startPosition的值
tempstr = Strright(Strright((doc.Query_String_Decoded(0)),=),=)
startPo sition = Int(tempstr)
End If
endPosition = startPosition + ResultPerPage - 1
还有这里:
Print <a href='http:// & ser & / & dbstr & /NewSearchAgent?OpenAgent&searchstring= & searchstr & &start= & ytm & '>
(里面的SEARCHSTRING是什么意思?)
谁能给解释一下,要不给我一个例子。谢谢了!
Query_String_Decoded是个CGI变量,怎么取呢?只要用当前文档就行了:dim doc as NotesDocument dim s as New NotesSession set doc = s.DocumentContext dim str as string str = doc.Query_String_Decoded(0) messagebox(str)试一下就知道了,至于后面的问题,SearchString是参数啊,上面的东东就是取他们的,试一下?!
你说SearchString是参数,但是它在你的搜索代理中只出现了一次,可以说是没有什么重要性。我觉得这里的SearchString应该写成searchstr,而这个searchstr就是搜索表单中的一个域,也就是事先取到的查询条件!!