Google-Like Searches In FileMaker

This article is a part of a series on Advanced Search Interfaces.

Using a single, global field and a fairly simple script, you can create a search-engine-like interface for searching the contents of a FileMaker Pro database.

Using a single, global field and a fairly simple script, you can create a search-engine-like interface for searching the contents of a FileMaker Pro database.

Place a global search field and button in the header of your list layout for search-engine-like search functionality.

Step One: Create a Global Search Field

Create a text field in any table. In the field options, set the new field to use global storage as shown in the figure below.

text

Under the storage tab in the field options, select the "Use global storage (one value for all records)" check box.

Tip: To keep your data tables clean, I recommend having a separate table to hold global fields, such as this one, that are not directly associated with a particular table. Global fields can be accessed from any context whether or not a relationship exists between the tables.

Step Two: Create the Find Script

Create a script that enters find mode, creates a new search request for each field you wish to search, copies the value of the global search field to each of those fields and performs a find.

  • Enter find mode (do not pause or specify find request).
  • For each field you want to search, use the “Set Field” script step to copy the value from the new global field.
  • Place a “New Record/Request” steps in between each “Set Field” step.
  • Perform Find.

Here’s a sample of how the script might look:

Enter Find Mode [  ]
Set Field [ Contacts::First Name; Globals::GlobalSearch ]
New Record/Request
Set Field [ Contacts::Last Name; Globals::GlobalSearch ]
New Record/Request
Set Field [ Contacts::Address Type 1; Globals::GlobalSearch ]
New Record/Request
Set Field [ Contacts::City 1; Globals::GlobalSearch ]
New Record/Request
Set Field [ Contacts::State Province 1; Globals::GlobalSearch ]
New Record/Request
Set Field [ Contacts::Postal Code 1; Globals::GlobalSearch ]
Set Error Capture [ On ]
Perform Find [  ]
Set Error Capture [ Off ]
If [ Get ( FoundCount ) = 0 ]
Show Custom Dialog [ Title: “No Records Found”; Message: “No records matched your search criteria.”; Buttons: “OK” ]
End If

Tip: Note the use of the Set Error Capture script step sandwiching the Perform Find step. This is to prevent the default FileMaker error which asks the user if they wish to modify the find request or cancel. Neither of these options will result in what the user would expect.

Step Three: Add Layout Objects

You can then place the global field and a search button to call your new script in your list view header, a pop-up window or wherever else you might find it useful.

That’s it! Now the user can simply enter search terms in the search field and click the search button and view their results without ever entering find mode and without knowing which fields to search.

Enhancement – Split Field Searching

One of the shortcomings of this script is that it will only find records that contain all the search terms in a single field. In other words, if you enter “ABC Plumbing Chicago”, it will only find records that contain the words “ABC Plumbing Chicago” all in the same field. If you want to be able to find a company record for “ABC Plumbing” located in “Chicago”, the script would need to split the phrase up and loop through each word. My article, Google-Like Searches In FileMaker – Non-Contiguous, explains a method to accomplish this.

If you have any questions or comments feel free to post a comment below or contact me directly.

25 Comments