Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Custom Recursive Function - Keyword search


This topic is 7338 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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...!

Posted

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

Posted

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.

Posted

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?

Posted

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

This topic is 7338 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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