logo

URL Syntax for advanced field level searching

OK, so we should all know by now that you can search a view by appending ?SearchView&Query=something to the end of its name in the url.

What do you do though when you want to get a little more advanced than that? For example, searching for "cash", but only in the "finance" field (note that the spaces would usually be replaced with + or %20):

/dir/db.nsf/aView?SearchView&Query=[finance] CONTAINS cash

Use the link below to test this out by searching Codestore for documents where the Keywords field contains "url":

area?SearchView&Query=[Keywords] CONTAINS url

Now, let's say we want to search for the user's query string but not in a certain field. This could be useful for something like searching for a name but not wanting to see everything that the person has ever written. So, if the author was stored in a field called "From", then the following would achieve this:

/dir/db.nsf/aView?SearchView&Query=Jake AND NOT [From] CONTAINS Jake

For example let's see how many documents in codestore contain the word "url" but NOT in the keyowrds field:

area?SearchView&Query=url AND NOT [Keywords] CONTAINS url

The links that you used above aren't exactly useful in real life so you need to compute these URLs yourself. You could do this in JavaScript but the more common method seems to be place an @Formula in the $$Return field of a search form; that contains a field called query. The formula used would be:

dbpath := @ReplaceSubstring(@Subset(@DBName; -1); "\\"; "/");
query := query + " AND NOT [Keywords] CONTAINS " + query;
"[/" + DBPath + "/area?SearchView&Query=" + query + "]"


How about finishing on something a bit more complicated? Say you have a search form with three fields (Query1, Query2 and Query3) for the user to enter two query strings and one query number. You want to find documents which contains the value from Query1 yet, not the Query2 value in Field1 or a value less than Query3 in Field2 (Field2 MUST be a Notes Number field). To do this replace "query" in the above example with the following:

query := "=" + Query1 + " AND NOT ([Field1] CONTAINS " + Query2 + " OR [Field2]<" + Query3 + ")"

Good luck chaps...

Note 1: You can extend this almost endlessly (as long as you don't go beyond the maximum length of a URL) with your own logic and by using other keywords like EQUALS instead of CONTAINS.

Note 2: Beware of what happens if the user enters search string that contains characters like reserved words or open/close square brackets; i.e searching for the following will/might cause errors:

  • tell me about the [ character


  • field names are causing me problems

Feedback

  1. Google style search queries

    Dear all,

    Being fond of the intuitive Google, I've made a $$return field, that translates a Google style search query into Notes style. This means you don't have to put operators like "AND" or "NOT" in the query. "AND" is automatically added, a hyphen can be used for "NOT". "OR" is the same in Notes as in Google. If anyone can do this in Javascript, I'd be more than happy.

    Here is the code:

    REM "this code works for maximum of 2 pairs of quotation marks, though you can extend using more subsets"; REM "hyphen can be part of a word, or can be used as NOT placed at the beginning of a search string, before a quotation mark and before a searchterm";

    t0000:=@LowerCase(@Trim(Your_Query_Field)); t000:=@If(@Begins(t0000;"-")=1;" "+t0000;t0000);

    REM "the hyphens that are not part of a word-combination are replaced by NOT and before and after quotation marks # (pound-keys) are placed"; t00:=@ReplaceSubstring(t000; "- " :" -" : "not\"" : " \"" :"\" " ; "not " :" not " : "not \"" : "#\"" :"\"#" ); t0:=@Explode(t00;"#");

    REM "the query is split into elements, where everything between quotation marks is a seperate element"; t1:=@Subset(t0;1); t2:=@Subset(@Subset(t0;2);-1); t3:=@Subset(@Subset(t0;3);-1); t4:=@Subset(@Subset(t0;4);-1); t5:=@Subset(@Subset(t0;5);-1);

    REM "Replace the space characters in an element that starts with a quotation mark by %20"; tt1:=@If(@Begins(t1;"\"")=1;@ReplaceSubstring(t1;" ";"%20");t1); tt2:=@If(@Begins(t2;"\"")=1;@ReplaceSubstring(t2;" ";"%20");t2); tt3:=@If(@Begins(t3;"\"")=1;@ReplaceSubstring(t3;" ";"%20");t3); tt4:=@If(@Begins(t4;"\"")=1;@ReplaceSubstring(t4;" ";"%20");t4); tt5:=@If(@Begins(t5;"\"")=1;@ReplaceSubstring(t5;" ";"%20");t5);

    REM "the elements are combined again with spaces in between them"; xt1:=@Trim(@Implode(@Unique(tt1:tt2:tt3:tt4:tt5:tt5);" "));

    REM "replaces spaces with AND and make corrections made for NOT and OR in combination with spaces"; xt2:=@ReplaceSubstring(xt1; " & " :" or " : "not " : " contains ": " " ; "%20%26%20" :"%20or%20": "not%20": "%20contains%20" : "%20and%20");

    "[/" + Your_Database + "/Your_Search_View?SearchView&Query=" + xt2 + "]"

    The search tips for users to use with this way of queriying. It is quite the same as the google syntax:

    search tips: - "AND" is automatically placed between your search terms - use a hyphen "-" to exclude words from your search - use asterix "*" as wildcard, e.g. 'codesto*' - use quotation marks for a combination of words e.g. "jake howlett"

  2. search view between two dates

    So this would be how I'd be searching documents created within two given dates...

    Interesting

    1. Re: search view between two dates

      [<a href="cmnts/3A764C7AA47970F380256C8E00669FF4?OpenDocument"> Like this</a>]

      Show the rest of this thread

  3. Hmm, doesn't work with for some reason

    Wel, I was just thinking, once again Jake saves my bacon.

    But the search doesn't work. And I think I got the URL right. Here is the resulting text: wSearch?SearchView&Query=docs%20[Country]%20CONTAINS%20France&SearchMax=0

    So I am looking for all documents containing the word docs and where field Country contains France, right?

    Result is: Query is not understandable.

    Hmm, I am stumped. Somebody?

    Lykle

      • avatar
      • Jake
      • Thu 27 Nov 2003

      Re: Hmm, doesn't work with for some reason

      I'm guessing you are missing an "AND":

      wSearch?SearchView&Query=docs%20AND%20[Country]%20CONTAINS%20France&SearchMax=0

      Jake

      Show the rest of this thread

  4. Boolean Search

    Hi,

    Anybody got any idea about how to build a search URL with combinations of 'AND' and 'OR' on the fly.

    thanks

    1. Re: Boolean Search

      for or you can use "|" and for and you can use "&"

    • avatar
    • Kristian
    • Sat 22 Nov 2008

    SearchURL breaks into 2 lines when sent to Outlook

    Hi.

    When sending an e-mail with an SearchView&Query URL-link to an Outlook user. The script works fine as long as the URL doesn't contains a "=[fieldname]". If the URL-link contains "=[" it will break into 2 pieces/lines (se bellow).

    Unfortunately I need to use that syntax when making field queries like in the following example, where I need to select documents where the field "Status" equals "3".

    1) Call richText.AppendText("http://server/dir/db.nsf/webSearchAll.us?SearchView&Query=[Status]=3&lan=us")

    2) Call richText.AppendText("http://server/dir/db.nsf/webSearchAll.us?SearchView&Query="+Chr(91)+"Status]=3&lan=us")

    3) Call richText.AppendText("http://server/dir/db.nsf/webSearchAll.us?SearchView&Query=%5bStatus%5d=3&lan=us")

    Common for the 3 examples are that the mail received in Outlook has a link that is broken into the following 2 lines:

    http://server/dir/db.nsf/webSearchAll.us?SearchView&Query

    =[Status]=3&lan=de

    I have used the property "PassThruHTML=True" but it didn't help. The only thing that helped was removing the "[]" but that doesn't help on my search.

    Any suggestions or help would be appreciated.

    Thanks in advance,

    Kristian

      • avatar
      • Jake Howlett
      • Mon 24 Nov 2008

      Re: SearchURL breaks into 2 lines when sent to Out

      PassThruHTML might not work but actually sending the email in HTML format might. Search this site for "html email" to see how.

      Jake

  5. From my current trial and error experience with Domino 7.0.3 FP1 on Linux it appears, that there is a hard limit of 512 characters for the query. To save valuable space here, it seems even more advisable to use the square bracket syntax instead of the "FIELD" keyword.

    Furthermore, according to Andre Guirard, "CONTAINS" does exactly the same thing as "=", so "=" is shorter is better. There is no syntax for "exactly equals".

    To save some more space, you can make use of the fact that no blanks are needed before and after brackets (except for readability). The "minified" version of the second example above would look like

    area?SearchView&Query=url AND NOT[Keywords]=url

    Doesn't make much of a difference here, but as soon as you start to provide a user configurable search using this technique, 512 characters turn out to be pretty limiting.

  6. Hi Jake, just wanted to let you know that my partner and I are huge fans of your site.

    I have a question regarding searching within date range

    I am trying to use the relational operators but getting this error:

    Relational operators are not supported in text fields

    here are the parameters we added:

    ?SearchView&query=[CALL_DATE>=07/17/2009]

    Note: Call_Date is a text field. The search is successfull without the > sign.

    Thanks and looking forward for your reply.

    All the best!

      • avatar
      • Jake Howlett
      • Mon 1 Mar 2010

      Hi Regina,

      Business partner or did you marry a developer?

      The search will be successful without the > as it's just comparing two strings in that case.

      If the CALL_DATE field isn't of type date I don't think you can do date comparison searches on it.

      Jake

Your Comments

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



Navigate other articles in the category "Views"

« Previous Article Next Article »
Control the look of the "No documents found" message   Auto-Launch a file attachment

About This Article

Author: Jake Howlett
Category: Views
Keywords: url; search;

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »