logo

New Response

« Return to the main article

You are replying to:

  1. Firstly, I'd like to salute Chris Thorpe for his ingenious solution and Jake for his invaluable site. I could have sat in front of my PC forever and never thought of doing search results grouping. Who said beer kills brain cells...

    I rebuilt the 'search results in groups' code as a LotusScript WebQueryOpen agent cos of the need for looping and easier debugging.

    My database uses a $$SearchTemplateDefault form to display the search results and uses the WQO agent to nicely format them. The fields 'ResultsGroups' and 'DisplayResultsTitle' are fields on the $$STD form which store the result of the WQO agent. The form also has the neccessary fields for holding TOTALHITS, COUNT, START etc. The search is done in a database on the fields 'Srnm', 'PrefNameMix_Case' and 'SalyNumb'. This text and other irrelevant information is deleted from the results title string cos the user doesn't need to see it. WQO code contains references to a CSS file.

    WQO Code follows: 'Declare Local Variables Dim nsSession As New NotesSession Dim ndContext As NotesDocument Dim strQuery As String Dim strQueryString As String Dim intHits As Integer Dim intCount As Integer Dim intStart As Integer Dim strResultsTitle As String Dim strResultsGroups As String Dim strStart As String Dim strCount As String Dim intLoops As Integer Dim intIndex As Integer On Error Goto OtherError

    'Get web document to manipulate Set ndContext = nsSession.DocumentContext 'Retrieve values from onscreen document intCount = ndContext.Count(0) intHits = ndContext.TotalHits(0) intStart = ndContext.Start(0) strQuery = ndContext.Query(0) strQueryString = ndContext.Query_String(0) 'Kill information user doesn't need to know strQuery = ReplaceSubstring(strQuery,"[Srnm]","") strQuery = ReplaceSubstring(strQuery,"[PrefNameMix_Case]","") strQuery = ReplaceSubstring(strQuery,"[SalyNumb]","") strQuery = ReplaceSubstring(strQuery,"Contains","") strQuery = Trim$(strQuery) 'Depending on how many hits we have for the query Select Case intHits Case 0 strResultsTitle = "<SPAN CLASS='WPTBoldBlue'>No documents found for </SPAN>" _ & "<SPAN CLASS='Blue'>'" & strQuery & "'</SPAN>" Case 1 strResultsTitle = "<SPAN CLASS='WPTBoldBlue'>1 document found for " _ &"</SPAN><SPAN CLASS='Blue'>'" & strQuery & "'</SPAN>" Case Is <= 10 strResultsTitle = "<SPAN CLASS='WPTBoldBlue'>Showing " & Cstr(intHits) _ & " of " & Cstr(intHits) & " documents for </SPAN><SPAN CLASS='Blue'>'" & strQuery & "'</SPAN>" Case Is > 10 'Kill the existing Start and Count variables cos we need to set our own strQueryString = ReplaceSubString(strQueryString,"&Start=" & Cstr(intStart),"") strQueryString = ReplaceSubString(strQueryString,"&Count=" & Cstr(intCount),"") 'Get the number of results groups If intHits Mod 10 = 0 Then intLoops = (intHits \ 10) Else intLoops = (intHits \ 10) + 1 End If 'Loop thru the number of times we need to make groups for 'e.g. If we return 78 results for a search, 'we need to make 8 results groups 'These would be 1-10, 11-20, 21-30, 31-40, 41-50, 51-60, 61-70, 71-78 'The 'All' results group is added at the end. For intindex = 1 To intLoops Select Case intIndex Case 1 strResultsGroups = "<A HREF='?" & strQueryString & "&Start=1&Count=10" & "'>1 - 10</A>" Case 2 If intHits => 20 Then strStart = Cstr((intIndex - 1) + 10) strResultsGroups = strResultsGroups & " | <A HREF='?" & strQueryString _ & "&Start=" & strStart & "&Count=10'>" & strStart & " - " & Cstr(intIndex * 10) & "</A>" Else strStart = Cstr((intIndex - 1) + 10) strResultsGroups = strResultsGroups & " | <A HREF='?" & strQueryString _ & "&Start=" & strStart & "&Count=10'>" & strStart & " - " & Cstr(intHits) & "</A>" End If Case intLoops strStart = Cstr(((intIndex - 1) * 10) + 1) strResultsGroups = strResultsGroups & " | <A HREF='?" & strQueryString _ & "&Start=" & strStart & "&Count=10'>" & strStart & " - " & Cstr(intHits) & "</A>" Case Else strStart = (((intIndex - 1) * 10) + 1) strResultsGroups = strResultsGroups & " | <A HREF='?" & strQueryString _ & "&Start=" & strStart & "&Count=10'>" & strStart & " - " & Cstr(intIndex * 10) & "</A>" End Select Next intIndex 'Add the 'All' results group strResultsGroups = strResultsGroups & " | <A HREF='?" & strQueryString _ & "&Start=1&Count=" & Cstr(intHits) & "'>All</A>" 'If we're at the last results group, set the count to be all and not 10 as used by 'the other results groups If (intStart + intCount) > intHits Then strCount = Cstr(intHits) Else strCount = Cstr(intStart + (intCount - 1)) End If strResultsTitle = "<SPAN CLASS='WPTBoldBlue'>Showing documents " & Cstr(intStart) _ & " to " & strCount & " of " & Cstr(intHits) & " for </SPAN><SPAN CLASS='Blue'>" _ & Chr$(34) & strQuery & Chr$(34) & "</SPAN>" Case Else 'Doh! End Select 'Only display results groups if there is something to show If Len(strResultsGroups) > 0 Then ndContext.ResultsGroups = "[" & strResultsGroups & "]" End If

    'Display the results title information ndContext.DisplayResultsTitle = "[ <BR>" & strResultsTitle & "]" Exit Sub OtherError: ndContext.DisplayResultsTitle = "Error '" & Error$(Err) & "' occurred at line " & Cstr(Erl) Exit Sub

    The function 'ReplaceSubString' I scrounged from the WWW.MARTINSCOTT.COM site so thanks must go to them.

    Function ReplaceSubstring(fullString As String, oldString As String,newString As String) As String Dim lenOldString As Integer Dim intPos As Integer On Error Goto ReplaceSubstringError lenOldString = Len(oldString) intPos = Instr(fullString, oldString ) Do While intPos > 0 And oldString <> "" fullString = Left (fullString, intPos - 1) & newString & Mid (fullString, intPos + lenOldString) intPos = Instr (intPos + Len(newString), fullString, oldString) Loop ReplaceSubstring = fullString Exit Function ReplaceSubstringError: ReplaceSubstring = fullString Exit Function End Function

    Hope this helps someone somewhere for something...

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: