Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Custom Recursive Function - Keyword search

Featured Replies

I just wanted to share a solution that I've worked up as a means of saying hello to the community -- I'm a member of the Philadelphia Area FileMaker's User Group, currently developing an architecture as a template for upgrading our solutions into 7 -- we decided we wanted to build our own help system rather than go third party.

Part of the "keyword search" feature is the need to handle multi-word searches as if each word in the search was a single search -- a simple PatternCount(HelpText; Keyword) wouldn't do it.

Using Developer 7, I created a custom recursive function called WordsCount, with two parameters -- Phrase and Word_to_search. Here's the function itself:

Let( [

numWords = WordCount(Word_to_search );

thisWord = LeftWords(Word_to_search; 1)

];  



If(numWords = 1; PatternCount (Phrase; thisWord);

PatternCount(Phrase;thisword) + 

WordsCount(Phrase; RightWords(Word_to_search; numWords - 1))

)



 



So far it appears to be testing out pretty well--I've been doing 1-5 word searches, I haven't tried copying-and-pasting War and Peace into the keyword field yet, but it's been pretty fast so far. 



The function just returns a total of all the occurrances of each word to the script or field that's called it--which means that outside of the function you can sort of "rank" different fields for  how important it is that the keywords appear in them, for example, if your help system has the following fields



Title

Help_Text



and you want to calculate the relevance of a record to give the number of times it appears in the title more weight than the number of times it appears in the text, you could have a calculated field named "relevance" that would say something like this:




(PatternCount (Title; gKeywords) * 100 +    // (Verbatum in title is ranked highest)

WordsCount (Title; gKeywords) * 50 +                 // (Any words appearing in title ranked high)

PatternCount(Help_Text; gKeywords) * 25 +         // (Verbatum in body is ranked well)

WordsCount(Help_Text; gKeywords)                    // (Each word in body ranked as-is)

) / WordCount(Help_Text)                                 // divided by number of total words in Text.

Anyhow, just thought I'd share... grin.gif any improvements/suggestions/modifications are of course welcome...!

Welcome Hack-it! (Hey my name Hackett!) Can you share what the problem is with just using patterncount()?

  • Author

well, the problem with patterncount that I've encountered (maybe I'm wrong) but if you wanted to search for two distinct keywords, PatternCount would only return the phrase you typed in, not the occurance of each word in the phrase.

I think I get it. So a function call:

WordsCount("search text"; "This is some text to search.")

would result in 2, 1 for each word matched?

  • Author

Right, whereas if you just did PatternCount you would return 0 because the phrase "search text" doesn't appear verbatum in the text block.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.