IBM®
Skip to main content
    Country/region select      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

A feature added in the Notes version 8.0 client but not much publicized, is the ability to perform a full-text search in a view using a Notes URL. This makes it simple to automate the creation of complex full-text searches for the user, perhaps based on information they enter in a dialog.

The URL syntax to perform the search is:

Notes://server/db/view?SearchView&query=yourQueryHere

There are no arguments to control stemming and sort order; these go to the defaults that the user last used. The server, db, and view components can be as usual for Notes URLs, and the query parameter must be escaped into valid URL characters. If the view is already open, the search occurs in the open view window.

The code below demonstrates how to create a search in this way based on information the user entered in a dialog:

Sub Initialize
       Dim session As New NotesSession

       Dim wksp As New NotesUIWorkspace

       Dim db As NotesDatabase

       Dim docDialog As NotesDocument

       On Error Goto oops

       
       Set db = session.CurrentDatabase

       Set docDialog = db.CreateDocument

       If wksp.DialogBox("searchAssistDialog", True, True, False, False, False, False, _

       "Enter Search Criteria", docDialog, True, False, True) Then

               Dim query, url$

               query = Evaluate({ @URLEncode("Domino"; Query) }, docDialog)

               url = "Notes://" + Replace(db.Server, "/", "%2f") + {/} _

               + db.ReplicaID + "/" _

               + wksp.CurrentView.View.UniversalID + {?SearchView&query=} + query(0)

               Call wksp.URLOpen(url)

       End If

       Exit Sub

oops:

       Msgbox "error " & Err & " line " & Erl & ": " & Error

       Exit Sub

End Sub

The agent code assumes that the form used in the dialog (searchAssistDialog in this case) contains a computed field named Query that calculates the query you want to perform, based on the field values entered by the user. Coming up with this query string is the most difficult part of this project, but this is different in every case, so there's little I can say here to help you, except to point out an example in the "Student FT Search Dialog" form in the free download that accompanies this article:
Views Part 1: User-Based Views and Query Assistant. The article describes other, harder ways of doing what we are now doing more simply using this new URL capability.

Of course, you could read the user's field values in the agent and calculate the query there, but I like an approach that lets you put everything that needs to know what fields are in the user assistant, into a single design element. If you prefer to use LotusScript to calculate the query, you could do it in the Queryclose event of the dialog form.

Note: the expression wksp.CurrentView.View.UniversalID doesn't work in desktop private views. You might want to modify this code to see whether wksp.CurrentView.View returns Nothing, and in that case use the view name or alias instead. In case the UNID is available, though, it's more reliable, since there may be duplicate view names or aliases.

Andre Guirard | 30 April 2009 06:00:00 AM ET | Caribou Coffee, Plymouth, MN, US | Comments (13)


 Comments

1) Wow
Dan King | 4/30/2009 8:43:05 AM

This is amazing Andre, I've been wanting to do this for ages, didn't think it was possible. There's an idea on ideajam I posted to add a viewftsearch type method, but this is effectively it.

Why hasn't this been publicised? I can give people meaningful dialogs to create searches now...!!!!!!

2) Automate full-text search in client app
Andre Guirard | 4/30/2009 10:23:07 AM

> Why hasn't this been publicised?

Because our developers will sometimes add things to let themselves accomplish what they want to do, and they need someone to come around with a little rubber mallet to tap them on the head and say "Hello! Might this not be useful to anyone else!?!?"

3) Absolutely Fantastic
David Goodchild | 4/30/2009 4:25:30 PM

Now if we can find a way to programmatically set the "Keep Sort Order" as well I can get rid of my spofu search results folders... do tell me it is possible!

4) Have I misread...
David Goodchild | 4/30/2009 5:12:02 PM

Having re-read the article, can you use the SearchOrder parameter? I'm not sure whether it is just left out above (but can be used), or whether it is not available in this scenario.

Off to bed but a nice bit of research for Friday!

5) Had to try...
David Goodchild | 4/30/2009 5:28:48 PM

and I understand how it works now, the whole querystring is passed into the search bar so SearchOrder is not possible. Had my hopes up for a minute but still very useful.

6) One more thing...
Vitor Pereira | 5/1/2009 7:54:47 AM

Could you get the little rubber mallet and go tap who ever did it on the head and get him/her to add the argument to control the sort order?

7) Can I always use %2f for the server separator in the Notes URL?
Jens Winkelmann | 5/13/2009 12:52:48 PM

When you compute the Notes URL you use Replace(db.Server, "/", "%2f") for the server part of the Notes URL.

The name of my server is'WinkelServer/WinkelOrga.

So your code will take WinkelServer%2WinkelOrga for the server part of the Notes URL.

But when I read the NotesDatabase.NotesURL property of a database, which is located on my server, I get the following result:

notes://WinkelServer@WinkelOrga/__C12575B500524291.nsf?OpenDatabase

Why does this property use @ for / and not %2f.

Sometimes the URL with @ has been worked on my computer and sometimes not.

So I decided to take only the common name of the server for the URL:

notes://WinkelServer/__C12575B500524291.nsf?OpenDatabase

Yes this will bring problems when the common name is not unique.

So should I use %2f as a separator. Does it always work.

8) Automate full-text search in client app
Andre Guirard | 5/14/2009 2:15:12 PM

Jens, I don't know; I don't see why it shouldn't work either way (with @ or %2f) except that @ does have a special meaning in URLs, so it might depend which program is interpreting the URL -- I'm guessing Notes will treat @ as a hierarchical name delimiter, whereas a web browser or the OS might treat it differently.

9) Does not work for me
Ingo | 7/14/2009 6:42:00 AM

Does not work for me with 8.0.2 Client.

Tried different ways...

Even a simple URL Open did not show the search results!!

e.g.:

Call ws.URLOpen("Notes://SERVER/test.nsf/VIEW?SearchView&query=Hello")

any ideas?

10) Automate full-text search in client app
Andre Guirard | 7/14/2009 12:26:38 PM

@Ingo: curious... what does it do instead of working?

11) Thank you...
tom oneil | 7/15/2009 3:05:01 PM

Next time I am in the Twin Cities... can I buy you a beer?

This worked splendidly!

12) Re: beer
Andre Guirard | 7/16/2009 10:58:28 AM

@tom, I don't do beer but I'll accept a latte. I'm in the phone book. :-)

13) URL Limit
tom oneil | 7/16/2009 4:35:16 PM

is there a limit to the search query URL (like the web?)

14) Re: URL length limit
Andre Guirard | 7/17/2009 10:24:56 AM

@Tom, yes there is; in the 1-2K neighborhood

 Add a Comment
Subject:
   
Name:
Comment:  (No HTML - Links will be converted if prefixed http://)
 
Remember Me?     Cancel

Search this blog 

Disclaimer 

    About IBM Privacy Contact