I design a database to search documents from large mail journaling databases through keyword like the sender ,recipients,subject ,start date to end data and text body.Every day the Server had nearly 3.5g data,I make a search test use my app database,I input subject and date to search 5 days message data.I took 3 hours to find the results.so badly.
my search code follow,how to make that efficient?
Function searchMJRN(servername As String,tmpdb As NotesDatabase,session As NotesSession,curdb As NotesDatabase,t_sender As String,t_receipt As String,t_subject As String,t_body As String,t_date_start As String,t_date_end As String)
Dim view As NotesView
Dim doc As NotesDocument
Dim t_doc As NotesDocument
Dim item As NotesItem
Dim tmpdoc As NotesDocument
Dim richitem As NotesRichTextItem
If Not tmpdb.IsOpen Then
Call tmpdb.Open(serverName$,tmpdb.FilePath)
End If
Set view=tmpdb.GetView("($BySenderQuery)")
Dim doEnterLoop As Boolean
doEnterLoop=True
Set doc=view.GetFirstDocument()
If Not doc Is Nothing Then
If t_date_end<>"" Then
Print "compare first doucment date to end date"
t_date_time_str$=doc.GetItemValue("PostedDate")(0)
t_date_str$=Strleft(t_date_time_str$," ")
If (Cdat(t_date_str$)> Cdat(t_date_end$)) Then
doEnterLoop=False
Else
doEnterLoop=True
End If
End If
Set t_doc=view.GetLastDocument()
'check date,not into endless loop
If t_date_start<>"" Then
If Not t_doc Is Nothing Then
Print "compare last document date to end date"
t_date_time_str$=t_doc.GetItemValue("PostedDate")(0)
t_date_str$=Strleft(t_date_time_str$," ")
If (Cdat(t_date_str$)<Cdat(t_date_start$)) Then
doEnterLoop=False
Else
doEnterLoop=True
End If
End If
End If
If doEnterLoop Then
Print "through date check,into other search conditions search"
Do While Not doc Is Nothing
Dim taglist List As Boolean
Dim tag As Boolean
tag=True
sender_str$=""
If t_sender$<>""Then
sender_str$=doc.GetItemValue("From")(0)
t_sender_tag=(Instr(1,sender_str$,t_sender$,5)>0)
taglist("sender")=t_sender_tag
End If
receipt_str$=""
If t_receipt$<>"" Then
Dim receipt_var As Variant
receipt_var=doc.GetItemValue("SendTo")
receipt_str$=""
For i=0 To Ubound(receipt_var) Step 1
If receipt_str$<>"" Then
receipt_str$=receipt_str$+","+receipt_var(i)
Else
receipt_str$=receipt_str$+receipt_var(i)
End If
Next
t_receipt_tag=(Instr(1,receipt_str$,t_receipt$,5)>0)
taglist("receipt")=t_receipt_tag
End If
subject_str$=""
If t_subject$<>"" Then
subject_str$=doc.GetItemValue("Subject")(0)
t_subject_tag=(Instr(1,subject_str$,t_subject$,5)>0)
taglist("subject")=t_subject_tag
End If
body_str$=""
If t_body<>"" Then
body_str$=doc.GetItemValue("Body")(0)
t_body_tag=(Instr(1,body_str$,t_body$,5)>0)
taglist("body")=t_body_tag
End If
date_time_str$=doc.GetItemValue("PostedDate")(0)
date_str$=Strleft(date_time_str$," ")
If t_date_start$<>""Then
t_date_start_tag=(Cdat(date_str$)>= Cdat(t_date_start$))
taglist("date_start")=t_date_start_tag
End If
If t_date_end$<>"" Then
t_date_end_tag=(Cdat(date_str$)<= Cdat(t_date_end$))
taglist("date_end")=t_date_end_tag
End If
Forall item_tag In taglist
tag=(tag And item_tag)
End Forall
If tag Then
Set tmpdoc=curdb.CreateDocument()
tmpdoc.Form="($MailDoc)"
tmpdoc.t_From=doc.GetItemValue("From")(0)
tmpdoc.t_EnterSendTo=doc.GetItemValue("SendTo")(0)
tmpdoc.t_Subject=doc.GetItemValue("Subject")(0)
tmpdoc.t_Date=doc.GetItemValue("PostedDate")(0)
Set richitem=New NotesRichTextItem(tmpdoc,"originaldoc")
Call richitem.AppendDocLink(doc,"","search message")
Call tmpdoc.Save(True,True)
End If
Set doc=view.GetNextDocument(doc)
Loop
Else
Print "not through date checkļ¼start search other databases"
End If
End If
End Function
any comments,thanks in advantage.