Second Signal Logo

NCT Simple Search Code

Sample NCT Search Implementation Code

The code listed below is used to accept a query from the user, execute the search, and display the results back to the user through the web browser. All the function calls are documented for you. As you can see, creating your own site search tool with NCT Search is easy.

Sub Initialize

' declarations
' these are the things that change from installation to installation
' so they get defined here, where its easy to change them
Const CONFIGDBSERVER = "WWW.THENORTH.COM/THENORTH"
Const CONFIGDBPATH = "clients\nctsearch\nctscfg.nsf"
Const EXECAGENTNAME = "NCTSEARCHEXEC"
Const keyname = "xxx"
Const keyvalue = "xxx"

Dim db As notesdatabase
Dim agent As notesagent

' get the db and search agent
Set db = New notesdatabase(CONFIGDBSERVER, CONFIGDBPATH)
If db Is Nothing Then Exit Sub
If Not db.isopen Then Exit Sub
Set agent = db.getagent(EXECAGENTNAME)
If agent Is Nothing Then Exit Sub

' create the parameter document
Dim doc As New notesdocument(db)
doc.query = "Database"
' no need to display more then we have to
doc.maxresults = 10
' since this is a NOTES client making the call,
doc.safeworkstationmode = 1
' make sure to put your key in....
doc.keyname = KEYNAME ' the constant defined above
doc.keyvalue = KEYVALUE ' the constant defined above
' then save your parameter document
Call doc.save(False,False)

' call the search agent
Dim docid As String
docid = doc.noteid
Call agent.runonserver(docid)

' re-load the parameter document (ick, but you have to do this to get back the results)
Set doc = Nothing
Set doc = db.getdocumentbyid(docid)

If doc Is Nothing Then Exit Sub

' print the results
If doc.hasitem("result_displaytextlist") Then
Forall txt In doc.result_displaytextlist
Print txt ' here's where you'd create the html link
' or notes docid if that is what you wanted to do
' you could, for example, create a table in a rich text field
' the show that field to the user
' these are the available returned fields on the parameter document
' result_docunidlist
' result_displaytextlist
' result_scorelist
' result_dbpathlist
End Forall
End If

' remove the parameter document
Call doc.remove(True)
End Sub