13 Replies Latest reply on May 4, 2011 11:45 PM by fabricen

    How can i highlight founds records after search

    caterpillen

      Summary

      How can i highlight founds records after search

      Product

      FileMaker Pro

      Version

      11.0v2

      Operating system version

      MAC OS 10

      Description of the issue

      How can i highlight founds records after search?

      In others words i wish to highlight or underline records afert search.
      i need to highlight the words i searched in the  texts that i found.

      sorry my english is not good i hope you can understand

      best regards

      Silvio

      Immagine_3.png

        • 1. Re: How can i highlight founds records after search
          philmodjunk

          Report an Issue is intended for reporting issues (possible bugs) that may require FileMaker inc. to correct in a future update or version release. Posts like yours are better served when posted to the FileMaker Pro forum (See tab above).

          Feel free to keep replying to this thread in order to get the help you need, but please keep that fact in mind for any future questions you might have.

          What you have posted doesn't look like you are finding records. Instead, it looks like you are highlighting matching text in a text field.

          You might experiment with Find/Replace (in the edit menu) to see if you can get it to highlight matching text for you. If you can get this to work for you manually, you should then be able to script the same process.

          • 2. Re: How can i highlight founds records after search
            caterpillen

            ok, sorry! :)

            my work is a database of 600 different articles.

            i would highlight in the text (after i searched) the word that i searched.

            something like the picture i posted

            thanks a lot

            • 3. Re: How can i highlight founds records after search
              MikhailEdoshin

              You can highlight (or apply any other styles) to text with, say, the Substitute function:

              Substitute( text, "argumi", TextStyleAdd( "argumi", Bold ) )

              In your case you wouldn't want to actually change your text, so you can create an unstored calculation that does this. You'll also have to script your find, so you can remember the word in, say, a global field:

              Highlighted Text = 

              Substitute( text, Searched Word, TextStyleAdd( Searched Word, Bold ) )

              You can place this calculated field over your real text field.

              • 4. Re: How can i highlight founds records after search
                philmodjunk

                I've used that method myself, but it has a serious draw back. Substitute is case sensitive and this can keep text that you want to be highlighted but which is capitalized differently from being changed to a Bold text style.

                Substitute( text, "argumi", TextStyleAdd( "argumi", Bold ) )

                and

                Substitute( text, "ARGUMI", TextStyleAdd( "ARGUMI", Bold ) )

                will "bold" different text in the text field.

                You can use [] to list multiple pairs of match and replace such as:

                Substitute( text,  [ "argumi", TextStyleAdd( "argumi", Bold ) ] ; [ "ARGUMI", TextStyleAdd( "ARGUMI", Bold ) ]  )

                But it is often difficult to list all the possible variations in capitalization this way.

                • 5. Re: How can i highlight founds records after search
                  MikhailEdoshin

                  Yes, I agree; and it won't work for a multi-word search either, let alone any more advanced search. Even for a simple single-word search it might highlight the sequence in the middle of a word, but this wouldn't be the match found by FileMaker, because FM only finds it in the beginning of a word. But it's dead simple too, so it's cost-benefit ratio is relatively high :) And thanks for the discussion, I just wrote down a couple of good ideas I'm going to think about :)

                  • 6. Re: How can i highlight founds records after search
                    caterpillen

                    Ok, thanks, i'm working but it's not easy

                    best regards :)

                    Silvio

                    • 7. Re: How can i highlight founds records after search
                      philmodjunk

                      A recursive custom function might be designed that could do this...

                      • 8. Re: How can i highlight founds records after search
                        philmodjunk

                        I couldn't resist tinkering with a custom function for this:

                        SelectedTextStyle ( WordList ; Text ; Style ) =

                        /* WordList : a return separated list of "match" words to be set to selected style if listed word is found in Text */
                        /* Text        : Text to be styled */
                        /* Style       : selected style to be applied to matching text */

                        Let ( [ NextWord = LeftWords ( text ; 1 ) ;
                                   Leader =  Left ( Text ; Position ( Text ; NextWord ; 1 ; 1 ) - 1 )
                                ] ;
                                Case ( IsEmpty ( Filter ( Lower ( Text ) ; "abcdefghijklmnopqrstuvwxyz" ) ) ; Text ;
                                            not IsEmpty ( FilterValues ( WordList ; NextWord ) ) ;
                                                      Leader &
                                                      TextStyleAdd ( NextWord ; Style ) & SelectedTextStyle ( WordList ; Right ( Text ; Length ( text ) - Length ( NextWord ) - Length ( Leader ) ) ; Style ) ;
                                             /* Else */ Leader & NextWord & SelectedTextStyle ( WordList ; Right ( Text ; Length ( text ) - Length ( NextWord ) - Length ( Leader ) )  ; Style )
                                          ) /* end case */
                                ) /* end let */

                        • 9. Re: How can i highlight founds records after search
                          caterpillen

                          i'm not an expert :)

                          i would like to know where and how i have to put this (??)

                          may you be more clear?

                          thanks a lot, Phil

                          silvio

                          • 10. Re: How can i highlight founds records after search
                            philmodjunk

                            Darn!

                            I deleted that message when I meant to edit a typo! That kills the posted message without even a confirmation check from the software!

                            Sighing and retyping.....

                            You need FileMaker Pro advanced to add a custom function. Do you have that?

                            If you do, you can copy and paste the above text from /* WordList... to /* end let */ into a new custom function definition. Then give it the function name and parameters to match: SelectedTextStyle ( WordList ; Text ; Style )

                            You can then use this function in an unstored calculation field that returns text or auto-entered calculation to style any single words in the field that match a list of single words passed to it as a parameter.

                            I used this calculation in an unstored calculation field to test it:
                            SelectedTextStyle ( gSelectionList ; gText ; Bold )

                            Where gSelectionList was a text field where I typed in a list of single words separated by returns and gText was the field with the unstyled text. (See TextStyleAdd in filemaker help for a list of styles that can be passed as a parameter either singly or in combination to this function.

                            • 11. Re: How can i highlight founds records after search
                              MikhailEdoshin

                              Hi Phil,

                              I wonder if it would be more effective not to loop over words in the text, but loop through search words instead. To filter out inter-word matching I'd try something like that:

                              Let( [
                                start = Position( text, word, 1, 1 ) - 2; /* to grab the previous letter */
                                first word at start = LeftWords( Middle( text, start, Length( text ) ) ];
                                If ( Left( first word at start, Length( current pattern ) ) = current pattern;
                                  /* highlight and continue */
                                 /* else don't highlight and continue */ ) )

                              I also cannot stop thinking how much better it would be to write a single regex that includes all variants :)

                              • 12. Re: How can i highlight founds records after search
                                philmodjunk

                                I'm afraid I don't see the advantage--which could just mean I don't fully comprehend your code!

                                • 13. Re: How can i highlight founds records after search
                                  fabricen

                                  For what it's worth, I posted a custom function some time ago, very similar to Mikhail's version.

                                  http://fmfunctions.com/functions_display_record.php?functionId=268