您的位置:首页 > 编程语言 > Go语言

Domino下实现仿Google搜索提示效果

2009-10-16 22:38 706 查看
[align=left] 随着Ajax的运用越来越广泛,越来越多的用户体验被提升,在Domino中应用Ajax实现Google搜索提示效果,在用户的使用过程中也是一种很实用的体验,下面将详细介绍下实现的思路和方法,仅供参考,以下代码在Domino6.5和ie 6中正常运行通过,效果如下图。
Code
Sub Initialize
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim cgi As NotesDocument
Dim docs As NotesDocumentCollection
Set cgi = Session.DocumentContext
Set db=Session.CurrentDatabase
Dim key As String
key= GetParameter("keyword",cgi.GetItemValue("Query_String_Decoded")(0)) 'GetParameter函数的作用是获取url中&keyword=的值
Set view = db.GetView("视图名")
Dim formalue As String
formalue={Form = "文档的表单名" & @contains(name;"}+Trim(key)+{")} 'name为查询文档的一个域
Set docs=db.Search(formalue,Nothing,0)
Print "Content-type: text/xml" '输出xml文件的表头
Print |<?xml version="1.0" encoding="GB2312" ?> |
Print "<result>"
If docs.Count<>0 Then
Dim words() As String
Dim i As Integer
i=1
Set doc=docs.GetFirstDocument()
While Not doc Is Nothing
words(i)=doc.name(0) 'name为查询文档的一个域,此处可根据具体情况而定
i=i+1
Set doc=docs.GetNextDocument(doc)
Wend

Dim x As Variant
x=Arrayunique(words) '去掉数组中的重复值
Dim cols As NotesDocumentCollection
Dim malue As String
Forall one In x
If one<> "" Then
malue={Form = "文档的表单名" & @contains(name;"}+Trim(one)+{")}
Set cols=db.Search(malue,Nothing,0)
Print "<first>" 'print出xml文件的格式,格式可根据自己的喜好更改
Print one
Print "</first>"
Print "<second>"
Print Cstr(cols.Count)
Print "</second>"
End If
End Forall
Else
Print "<first>"
Print key
Print "</first>"
Print "<second>"
Print "0"
Print "</second>"
End If
Print "</result>"
End Sub
[/align]
上面的代码只是为了粗略的实现Google搜索提示的效果,在真正的使用这种效果的时候代理查询要更复杂,前台展示的效果要更细腻,由于代码写的比较仓促,以致根本来不及估计编码规范,看得懂就好。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: