We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28528
    • 31 Posts
    stevechilvers Reply #21, 14 years ago
    This is exactly what I needed for a new site I’m working on smiley

    Only problem I’m having is with the ’Search Again’ form on the results page. It just seems to redirect to the home page?

    Steve
      • 30023
      • 172 Posts
      It should send you to the same page - the URL being generated via $modx->makeUrl($modx->documentIdentifier)).

      If you can post (or PM) the URL I can have a quick look to see what mark-up is being generated.

      -- Tim.
        • 8694
        • 61 Posts
        The snippet works very well. The best search snippet for MODx Revolution.
          • 30023
          • 172 Posts
          Thanks!

          Version 1.4 for Evolution is now available which includes the facility for a user to use "quoted strings" to specify exact matches e.g. whereas typing big gold coins takes all three words independently typing big "gold coins" insists that the latter two words are treated as one term.

          I also have a version of 1.4 for Revolution, which I am refering to as 2.0. It doesn’t actually have any extra features - it just works with the Revolution API.

          This doesn’t mean I’ll be dumping maintainence of the Evolution version as for commercial sites I am still using MODx Evolution, and will be for the forseeable future. I actually intend - should it remain feasible - combining the two versions so the snippet can detect which MODx branch it is running on, and hence choose the correct API.

          See http://timspencerweb.co.uk/modx-search

          -- Tim.
          • I actually intend - should it remain feasible - combining the two versions so the snippet can detect which MODx branch it is running on, and hence choose the correct API.
            Now that will be a very useful function for all third-party developers!
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 31088
              • 14 Posts
              [edit]just so this doesn’t come up in search results, and confuse people, I’m editing my post.
              It turns out it was my own unknown installation error. The snippet works brilliantly smiley Sorry for the bother.[/edit]


              -g
                • 30023
                • 172 Posts
                Can you post (or PM) a URL?

                As I understand it, your problem shows in v1.4, but not 1.3 (?).

                -- Tim.
                  • 31088
                  • 14 Posts
                  Hello Tim,
                  Thank you for getting back to me.

                  I re-installed 1.4 so I could PM a link to you, and for some reason it is working fine now...
                  Must have been a mistake on my part.
                  Honestly I don’t know where I went wrong, I had tried re-installing already huh

                  Anyway, turned out to be an unknown user error on my part. Apologies embarrassed

                  This is a really great snippet, it’s just exactly what I needed.
                  Thanks again.

                  -G
                    • 11139
                    • 34 Posts
                    A really useful snippet. Many thanks.

                    One query: is it possible to not include containers in the output? So if I search a subtree of resources like this:
                    pets
                    dogs
                    Fido
                    Rover
                    cats
                    Felix
                    then it will report Fido, Rover and Felix, the individual pets, but not the container pages ’pets’ ’dogs’ and ’cats’.

                    BTEW it was very easy to setup. Great work.

                    Thomas
                      • 30023
                      • 172 Posts
                      At first glance, the easiest but crudest solution is to manually unset the searchable flag on all containers.

                      As regards automatic solutions, either:

                      1) Write a plugin attached to the onDocFormSave event to set all containers to be unsearchable (not a complex piece of code, but you’ll need to know PHP and be aware of how to write plugins for events)

                      or

                      2) Feed the results of the search snippet back into Ditto and make it filter out all containers.

                      Make these chunks:

                      {{searchStartTpl}} =
                      [!Ditto? &documents=`

                      {{searchEndTpl}} =
                      ` &where=`isFolder=`0` !]

                      {{searchTpl}} =
                      [+id+],


                      ... and refer to these templates in the call to the search snippet.

                      &searchStartTpl=`searchStartTpl` &searchEndTpl=`searchEndTpl` &tpl=`searchTpl`


                      I’ve not tested this, so treat it as nudge in the right direction rather than a definitive answer! Note that &documents will have an extra comma at the end, but hopefully Ditto won’t mind about this. This code is for Evo, but I think it will work for Revo also.


                      -- Tim.