URL Syntax for advanced field level searching

Jake Howlett, 17 October 2000

Category: Views; Keywords: url search

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: