We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9145
    • 13 Posts
    Hi,

    I have a site with a large list of products. What I’ve done is created a TV called "product_searchwords" for the product page templates so that I can input keywords (or tags) for each product. Now I’m just trying to create a search that will only search for the contents of that TV, so if the search finds one of those keywords, then that product will show up in the search results. Is this even possible with AjaxSearch? I know the documentation says you can search for TVs, but can you search for ONLY TVs? Or do I need to use Wayfinder or Ditto?

    Thanks!
      • 4310
      • 2,310 Posts
      Certainly can be done with Ditto.
      Search form that POSTS to a Ditto summary page.
      Ditto call uses the search POST data as the &tags=
      The &tagData= would be product_searchwords
      You’d need a snippet to retrieve the POST data e.g.
      <?php
      $val = $_POST['name_of_data'];
      echo "$val";
      return;
      ?>

      I’ve used this basic method on a couple of sites.
      If you need any more help, just ask.
        • 4749
        • 623 Posts
        That’s a great concept. I would love to be able to use it, but I have a client that wants to use the ajax live search to display only one result - the exact phrase from the TV.
          The MODx has you...
          Utah Web Design
          • 10449
          • 956 Posts
            • 9145
            • 13 Posts
            @bunk58

            Thanks for the quick response! Sorry it took me so long to get back...

            Anyway, I apologize, I am new to ModX but here’s what I made of your comments:

            I set up a simple search form:
            <form action="search_results.html" method="post">
            	<input name="search_data" type="text" />
            	<input type="submit" value="Search" />
            </form>


            search_results.html looks like this:
            [[Ditto? &tagData=`product_searchwords` &tags=`[[search_data]]` ]]


            and my search_data snippet looks like this:
            <?php
            $val = $_POST['search_data'];
            echo "$val";
            return;
            ?>


            With this setup, I get "No documents found" every time. Where did I go wrong?

            Thanks!
              • 4310
              • 2,310 Posts
              Try...
              [!Ditto? &tagData=`product_searchwords` &tags=`[[search_data]]` &tagMode=`onlyTags`!]

              Caching has to be alternated, this should return the POST value before the Ditto snippet is parsed.
                • 9145
                • 13 Posts
                Okay, I replaced my Ditto call with yours, but I still get "No documents found."

                I also tried changing the layout of my keywords in the product_searchwords TV. Do they need to be separated by commas or just spaces?

                Thanks.
                  • 4310
                  • 2,310 Posts
                  Eyes down for a full house and away we go.
                  On the pages you want the search form code (could be in a chunk or template) =>
                  <form action="[~20~]" method="post" enctype="multipart/form-data">
                  	<input name="search" type="text" />
                  	<input type="submit" value="Search" />
                  </form>

                  A snippet named search_data =>
                  <?php
                  $val = $_POST['search'];
                  echo "$val";
                  return;
                  ?>

                  On the search landing page [~20~] in my example Ditto call above =>

                  [!Ditto? &startID=`3` &display=`all` &tpl=`ditto_tpl` &sortBy=`id` &sortDir=`ASC` &commentsChunk=`` &depth=`3` &showInMenuOnly=`1` &noResults=`No other products found` &tagDelimiter=`,` &tagData=`range` &tagMode=`onlyTags` &tags=`[[search_data]]`!]

                  Where in my example range is the name of the TV you are looking for matches and ditto_tpl is the name of your Ditto summary template chunk.
                  I’ve checked this on a live site and it seems to work okay.
                    • 7231
                    • 4,205 Posts
                    Note: Ditto has the Request Extender that will allow you to set any of Ditto’s parameters via the request string (it actually uses the $_REQUEST so it will work with either POST or GET). All you need to do is at &extenders=`request` to the Ditto call and then use a ditto_ prefix to your form variables. (I normally use the same method as described earlier to avoid the ditto_ prefix, but you can edit the extender and use some other prefix if you want).

                    So if the request has ditto_parents=10 it will set the parents parameter in the Ditto call to 10. If you have multple ditto calls you will need to append a ditto ID to the call as well.

                    Also yo may be interested in TVExplorer, it is for searching TVs (and other content). I have never used it officially but have seen some cool results from others who have used it. It uses Ditto as an engine so it may be similar to what you are doing already.

                    And, as stated, AS 1.8 will do this as well.
                      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                      Something is happening here, but you don&#39;t know what it is.
                      Do you, Mr. Jones? - [bob dylan]