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

    I am using EVO 1.0.4 with AjaxSearch 1.9.1.

    I have setup a search that is throwing interesting results - lots of product items are being excluded and I am not sure what I am missing in my calls.

    The site includes lots of product items (children) that are displayed on their category (parent) pages in html tables via wayfinder menu calls - the actual children pages are excluded from the search by excluding their modx templates)

    The product items info is taken from the following fields:

    Page Title = Part Number
    Description = Descriptions
    (nothing comes from content for the actual product items)

    Some of the content yield’s no results.

    Here’s an example:

    On one page I have an html table displaying 3 products
    item1
    item2
    item3

    Searching item1 and item3 yield’s no results - whereas Searching item2 works.

    Searching for info from their descriptions such as:
    - "Corrugated" returns no results where as searching for "Corrugated Flexible" works
    - "Smooth Bore" returns no results where as searching for "Smooth Bore Flexible" works

    My AjaxSearch calls are as follows...

    Search Form in Header:

    [!AjaxSearch? &landingPage=`6` &ajaxSearch=`0` &showResults=`0` &showIntro=`0` &addJscript=`0`
    &tplInput=`@FILE:assets/snippets/ajaxSearch/templates/custom/search-form-hdr.html`
    !]
    


    Search Call on the landing page:

    [!AjaxSearch? &showInputForm=`0` &ajaxSearch=`0` &showIntro=`0` &pagingType=`0` &highlightResult=`0` &grabMax=`20`
    &rank=`pagetitle:50,alias:20`
    &filter=`template,9,2|template,7,2`
    &tplInput=`@FILE:assets/snippets/ajaxSearch/templates/custom/search-form-pg.html`
    &tplGrpResult=`@FILE:/assets/snippets/ajaxSearch/templates/custom/grpResult.html`
    &tplResult=`@FILE:/assets/snippets/ajaxSearch/templates/custom/result.html`
    &tplResults=`@FILE:/assets/snippets/ajaxSearch/templates/custom/results.html`
    &tplPaging0=`@FILE:/assets/snippets/ajaxSearch/templates/custom/paging0.html`
    &tplPaging1=`@FILE:/assets/snippets/ajaxSearch/templates/custom/paging1.html`
    &tplPaging2=`@FILE:/assets/snippets/ajaxSearch/templates/custom/paging2.html`
    !]


    Any ideas?

    Thanks in advance.
      Web design Adelaide
      http://gocreate.com.au
      • 5811
      • 1,717 Posts
      On one page I have an html table displaying 3 products
      FDP16
      FDPS16
      FDPI19

      Searching FDP16 and FDPI19 yield’s no results - whereas Searching FDPS16 works.
      Could you check some things:
      - FDP16 and FDPI19 have the same template file as FDPS16
      - these templates aren’t the template #7 or #9
      - the documents are searchable and published and public


      [!AjaxSearch? &landingPage=`6` &ajaxSearch=`0` &showResults=`0` &showIntro=`0` &addJscript=`0`
      &tplInput=`@FILE:assets/snippets/ajaxSearch/templates/custom/search-form-hdr.html`
      !]
      Here, as the non-ajax mode is set, &addJscript=`0` is useless.

      [!AjaxSearch? &showInputForm=`0` &ajaxSearch=`0` &showIntro=`0` &pagingType=`0` &highlightResult=`0` &grabMax=`20`
      &rank=`pagetitle:50,alias:20`
      &filter=`template,9,2|template,7,2`
      &tplInput=`@FILE:assets/snippets/ajaxSearch/templates/custom/search-form-pg.html`
      &tplGrpResult=`@FILE:/assets/snippets/ajaxSearch/templates/custom/grpResult.html`
      &tplResult=`@FILE:/assets/snippets/ajaxSearch/templates/custom/result.html`
      &tplResults=`@FILE:/assets/snippets/ajaxSearch/templates/custom/results.html`
      &tplPaging0=`@FILE:/assets/snippets/ajaxSearch/templates/custom/paging0.html`
      &tplPaging1=`@FILE:/assets/snippets/ajaxSearch/templates/custom/paging1.html`
      &tplPaging2=`@FILE:/assets/snippets/ajaxSearch/templates/custom/paging2.html`
      !]
      &tplPaging1=`@FILE:/assets/snippets/ajaxSearch/templates/custom/paging1.html`
      &tplPaging2=`@FILE:/assets/snippets/ajaxSearch/templates/custom/paging2.html` are useless as the pagingType used is 0.


      Could you add &debug=`1` in your snippet calls, run a search with "FDP16".
      Then open the debug/ajaxSearch_log.txt file, find the SQL statement executed and run this statement under PhpMyAdmin. Do you get the awaited results ? Use personal message to give me the details.
        • 21417
        • 486 Posts
        Hi Coroico,

        Thanks so much for getting back to me so quickly.

        FDP16 and FDPI19 have the same template file as FDPS16
        Yes, all 3 product items have the same template.

        these templates aren’t the template #7 or #9
        Well all 3 product items do use template #7 but they are not displayed on individual product pages - they are displayed collectively from a wayfinder menu call in an html table on their parent page which uses template #8 (as per this link
        http://propipesupplies.com.au/products/pro-pipe/flexible-drain-pipe.html
        )

        Eg - the nested structure is as follows:
        Sub Category
        - item1
        - item2
        - item3

        The site does not feature individual products on pages - products are included in tables on their parent pages.

        I figure that’s not an issue as searching "item2" works - as does searching "Corrugated Flexible" (from the FDP16 row).

        the documents are searchable and published and public
        Yes, all 3 items are searchable and published - (show in menu is unchecked for all 3).

        I have tweaked the calls with your suggestion for removng &addJscript=`0` and &tplPaging1= and &tplPaging2=

        I have added &debug=`1` to both calls

        I opened the debug/ajaxSearch_log.txt file - but cannot find the SQL statement to run in statement under PhpMyAdmin. I don’t know anything about sql - I did a quick google search but couldn’t work out what I was looking for. Sorry about that.

        I will pm you the log file shortly - let me know the sql statement to run and I will run it.

        Thank you Coroico.
          Web design Adelaide
          http://gocreate.com.au
          • 5811
          • 1,717 Posts

          Well all 3 product items do use template #7 but they are not displayed on individual product pages
          &filter=`template,9,2|template,7,2`
          By using &filter=`template,7,2` you exclude all the documents related with the template #7. So the search doesn’t occur in documents FDP16, FDPS16, FDPI19

          You use a snippet (wayfinder) to set up the html table of products, so as AjaxSearch can’t find in dynamic content (the data should exist in the database, not built on fly), no results can be found in the content of the parent page.

          Searching for info from their descriptions such as:
          - "Corrugated" returns no results where as searching for "Corrugated Flexible" works
          - "Smooth Bore" returns no results where as searching for "Smooth Bore Flexible" works
          I think that "Corrugated Flexible" and "Smooth Bore Flexible" works because you have the word "flexible" in the description of your parent page "Flexible Drain Pipe". The search doesn’t occur in the content of this page (the html table of products) but only in the pagetitle and/or description (default fields where the search occurs).

          If you add &whereSearch=`content:content` (so you exclude the search in the pagetitle) I am pretty sure you won’t get any results.

          Regarding &debug=`1` to get the sql statement you need to run a search before.
          Don’t forget to remove this option when your site is on line.


            • 21417
            • 486 Posts
            Hi coroico,

            Ah I see - I thought AjaxSearch would just read the content on the page, whether it was static or dynamic.

            Why do you think item2 works in that table? Its kind of weird that 1 out of 3 would work that’s not mentioned anywhere else on the site. I will PM you the log file info fyi.

            Can you think of a workaround to make it work in this situation with wayfinder info without having to link to individual product pages? There are 120 or so products with more to be added so doing it statically is not a realistic option.

            Seems crazy in this day and age of dynamic content.

            Based on what you said about excluding wayfinder info, I think you are spot on re "Flexible" being picked up from the page content.

            You’re right - adding &whereSearch=`content:content` stopped item2 working.

            I’m not sure how to proceed now.

            Any ideas?
              Web design Adelaide
              http://gocreate.com.au
              • 21417
              • 486 Posts
              Or is possible to remove the filter and allow searching the pages with template 9 and 7, but to somehow include the links to their parent document?

              Or somehow index a page when it is saved and store it statically purely for searching purposes?

                Web design Adelaide
                http://gocreate.com.au
                • 5811
                • 1,717 Posts
                Yes, allow the search in children documents like FDP16, FDPS16, FDPI19, so don’t use &filter=`template,9,2|template,7,2` if the children documents use these templates.

                And to include the links to their parent document in the search results do as follow:

                1/ create a snippet "GetCategoryLink" and copy/paste the following code in this snippet:
                <?php
                $id = (isset($id)) ? $id : $modx->documentIdentifier;  // get the id of the document
                $parent = $modx->getParent($id); // get the parent information
                $url = $modx->makeUrl($parent['id']); // make a link to the parent
                echo $url; // display the link
                ?>
                This imply that the category is always provided by the parent document. And you definitively loose the possibility to highlight the results.

                2/ then in your assets/snippets/ajaxSearch/templates/custom/result.html` template file replace:
                <a class="[+as.resultLinkClass+]" href="[+as.resultLink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>
                by
                <a class="[+as.resultLinkClass+]" href="[[GetCategoryLink? &id=`[+as.id+]`]]" title="[+as.longtitle+]">[+as.pagetitle+]</a>


                By doing this the link to the children document will be replaced by a link to the parent. [+as.id+] give the id of the child document and [[GetCategoryLink? &id=`[+as.id+]`]] return the url to the parent document

                and replace the snippet call of the landing page by:
                [!AjaxSearch? &showInputForm=`0` &ajaxSearch=`0` &showIntro=`0` &pagingType=`0` &highlightResult=`0` &grabMax=`20`
                &rank=`pagetitle:50,alias:20`
                &tplInput=`@FILE:assets/snippets/ajaxSearch/templates/custom/search-form-pg.html`
                &tplGrpResult=`@FILE:/assets/snippets/ajaxSearch/templates/custom/grpResult.html`
                &tplResult=`@FILE:/assets/snippets/ajaxSearch/templates/custom/result.html`
                &tplResults=`@FILE:/assets/snippets/ajaxSearch/templates/custom/results.html`
                &tplPaging0=`@FILE:/assets/snippets/ajaxSearch/templates/custom/paging0.html`
                !]
                Here I have simply removed the &filter parameter and the useless parameters like &tplPaging1 and &tplPaging2.

                Let me know if it is ok. If yes, I accept a beer grin

                  • 21417
                  • 486 Posts
                  Hello again coroico,

                  Now you’re talking!

                  Thank you so much - this sounds like a great solution but is throwing the following error when
                  <a href="[[GetCategoryLink? &id=`[+as.id+]`]]" title="[+as.longtitle+]">[+as.pagetitle+]</a>
                  is in the custom result.html file:

                  « MODx Parse Error »
                  MODx encountered the following error while attempting to parse the requested resource:
                  « `` is not numeric and may not be passed to makeUrl() »
                   
                  Parser timing
                    MySQL: 	0.0388 s	(8 Requests)
                    PHP: 	0.1438 s	 
                    Total: 	0.1825 s


                  At some point I obviously don’t want the child document to be linked to its parent, otherwise every page would link further up the chain wouldn’t it? See the attached image of the tree (it’s pretty deep and complex - some products are on their own page while some are combined with others).

                  If I throw some more beers at you once this is working would you be able to tweak the code slightly for me so that it uses the link of a template variable (called "xy-search-link") rather than a direct parent document - if nothing exists in the TV, the page link is as normal - otherwise it takes the link in the TV.

                  That would be amazing and allow me to carefully choose the link.

                  Beers will be coming, don’t you worry about that!

                  Thanks so much Coroico.
                    Web design Adelaide
                    http://gocreate.com.au
                    • 21417
                    • 486 Posts
                    Hi Coroico,

                    OK, this is officially above my head.

                    I think a TV is the way to go but have absolutely no idea how to get TVs working with AjaxSearch.

                    What I would like to do is only apply the "xysearchlink" TV to docs with the Template 7 or 9, and to everything else (eg if the TV is empty / non existant) serve up:
                    <a href="[+as.resultLink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>


                    I have tried the following in my landing page AjaxSearch calls all without success:
                    &withTvs=`+:xysearchlink`
                    &withTvs=`xysearchlink`


                    And in my result template:
                    <a href="[+xysearchlink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>


                    They just return an empty search string that links to the home page.

                    I also tried with PHx but I have no idea what I am doing there:

                    PHx Isnot
                    [+phx:if=`[+xysearchlink+]`:isnot=``:then=`<a href="[+xysearchlink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>`:else=`<a href="[+as.resultLink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>`+]


                    PHx Is
                    [+phx:if=`[+xysearchlink+]`:is=``:then=`<a href="[+as.resultLink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>`:else=`<a href="[+xysearchlink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>`+]


                    I have had success in using DITTO as per the solution on this page http://modxcms.com/forums/index.php/topic,28286.msg271241.html#msg271241 but not sure if that is the right way to do it:
                    <a href="[[Ditto? &documents=`[+as.id+]` &tpl=`ajaxsearch-link`]]" title="[+as.longtitle+]">[+as.pagetitle+]</a>


                    What kind of beer do you drink?

                    Thanks Coroico.
                      Web design Adelaide
                      http://gocreate.com.au
                      • 5811
                      • 1,717 Posts
                      Thank you so much - this sounds like a great solution but is throwing the following error when
                      <a href="[[GetCategoryLink? &id=`[+as.id+]`]]" title="[+as.longtitle+]">[+as.pagetitle+]</a>
                      is in the custom result.html file
                      Apologies, the correct code should be:
                      <?php
                      $id = (isset($id)) ? $id : $modx->documentIdentifier;  // get the id of the document
                      $parent = $modx->getParent($id); // get the parent information
                      $url = $modx->makeUrl($parent['id']); // make a link to the parent
                      echo $url; // display the link
                      ?>
                      You need to pass the id of the document to getParent to get the parent id.
                      I have corrected the previous post. Tested on my laptop.

                      At some point I obviously don’t want the child document to be linked to its parent, otherwise every page would link further up the chain wouldn’t it? See the attached image of the tree (it’s pretty deep and complex - some products are on their own page while some are combined with others).
                      Ok I understand.
                      What I would like to do is only apply the "ppsearchlink" TV to docs with the Template 7 or 9, and to everything else (eg if the TV is empty / non existant) serve up:
                      Code:

                      <a href="[+as.resultLink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>
                      Rather to add a TV in each product may be it could be better to retreive the category document by an another way. What are the difference between the category product document and a product document ? May be the category product document use a specific template which is not the same used by the children documents ? If it is the case, by modifying the GetCategoryLink snippet, starting from any document, we could search a document in the upper hierarchy with this template number. If this document is found, the snippet return the link to the category otherwise run as usual and return the link to the current document. Is it possible to do this distinction between documents ?