We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10405
    • 288 Posts
    Have just added AjaxSearch (version 1.8.3) as a snippet onto my web page, but by default although I enter in relevant search terms (for which I know there are results) it works on the search but comes up with no results.

    How does it need to be configured? Ideally it should go to a new page which displays the search results (highlighted if possible).

    I noticed that there is a section in the script for configuring this:

    $cfg[’resultsPage’] = $dcfg[’resultsPage’];

    It says you can add in a number for using a separate page for results (which is what i want) but there’s no explanation as to where to put this number or where to specify the name of the results page.

    There doesn’t seem to be any explanation with the script itself as to how to set it up, so if anyone is aware of any documentation or can provide some information on setting it up that would be really helpful. Thanks!
      • 5811
      • 1,717 Posts

      Here is the wiki documentation: http://wiki.modxcms.com/index.php/AjaxSearch
        • 10405
        • 288 Posts
        Many thanks, I will take a look through that.
          • 10405
          • 288 Posts
          Not getting anywhere with the AjaxSearch-

          I’ve placed this code in my page template and it appears in the page ok:

          [!AjaxSearch? &ajaxSearch=`0` &AS_landing=`70`!]

          70 is the ID of searchresults.html (my search results page).

          I can run the search query from the original page, it appears to try and do something, and it successfully redirects to searchresults.html, but doesn’t show any results- for terms which I know exist many times in the site.

          All the pages on the site I want to search are both Published and Searchable.

          Any ideas?
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Do you have a corresponding AjaxSearch snippet on page 70?
              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
              • 10405
              • 288 Posts
              I don’t- should I put the same code somewhere on that page? If so, where should it go?

              Thanks

              (Ah, hang on, I’ve added this code to the search results page...)

              [!AjaxSearch? &ajaxSearch=`0` &AS_showForm=`0`!]

              However although it seems to be displaying the search term results, the formatting is odd- the results are all bunched up together as if they’re crammed into a small div. huh
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Wherever in the page content you want the search results to appear. You’ll want to have some parameters to control what shows and what doesn’t; for example you probably don’t want the search form along with your results, so use
                [!AjaxSearch? &ajaxSearch=`0` &AS_showForm=`0`!]
                  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
                  • 10405
                  • 288 Posts
                  Thanks, I seem to have the search results now, but despite placing the snippet call inside a perfectly large container, the results bunch up together so aren’t at all readable...
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    well, without a link to see the results, it’s a little hard to say. You can, however, create chunk tpls for the output; create a chunk for the outer container for all the results and specify it with &tplResults=`chunkname`, and another chunk for each individual item with &tplResult=`otherchunkname`. Style to suit.

                    I suspect your problem is in the CSS; do a "view source" in your browser to see what you need to style.
                      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
                      • 10405
                      • 288 Posts
                      Didn’t work I’m afraid. In the searchresults.html I edited the ciode thus:

                      [!AjaxSearch? &ajaxSearch=`0` &AS_showForm=`0` &tplResults=`resultsholder` !]

                      I created a chunk called resultsholder, and used some code I found in a layout.tpl.html file in the AjaxSearch templates folder:

                      [+as.showForm:is=`1`:then=`
                      <form [+as.formId+] action="[+as.formAction+]" method="post">
                      <fieldset>
                      <input type="hidden" name="advSearch" value="[+as.advSearch+]" />
                      <label for="ajaxSearch_input">
                      <input id="ajaxSearch_input" class="cleardefault" type="text" name="search" value="[+as.inputValue+]"[+as.inputOptions+] />
                      </label>
                      <label for="ajaxSearch_submit">
                      <input id="ajaxSearch_submit" type="submit" name="sub" value="[+as.submitText+]" />
                      </label>
                      </fieldset>
                      </form>
                      `+]
                      [+as.showIntro:is=`1`:then=`
                      <p class="ajaxSearch_intro" id="ajaxSearch_intro">[+as.introMessage+]</p>
                      `+]
                      [+as.showResults:is=`1`:then=`
                      [+as.results+]
                      `+]

                      What’s happened now is that the search results don’t show at all... huh

                      Also how do I create a chunk for each individual item in the search results- as I can’t see how many search results there are (due to the formatting of the results)?

                      I then also tried [!AjaxSearch? &ajaxSearch=`0` &AS_showForm=`0` &tplResults=`{{resultsholder}}` &tplResult=`{{resultholder}}` !] with both the chunks empty of any code (I’m not sure what code they should contain?) but again the search results show all bunched up without any formatting...