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

    A partner has made a snippet to connect to a SolR server.
    It's very specific, not at all an Extras class component.

    To be fully clear Modx and this custom snippet uses a custom DB on our web server synchronized with the SolR server DB (importing only what is necessary) containing the whole 160000+ articles from our erp (Odoo)

    ok

    This 'Solr' snippet format and send query to SolR and receives the xml response files, parse it and creates what we need (mostly placeholders containing row data) this will mimic a faceting search system that is now working with plain text parameters in the snippet call.

    It's plan to be used on ModX pages using modx tags as parameters to be passed to the snippet
    Here's an example :
    [[!solr?&fabricant_facet=`XYZ`& product_type =`HPLC`&rows=`500`]] 

    works fine and generate a solr query with the 2 facets 'XYZ' and 'HPLC'

    BUT if I try this (what is the final goal) :
    [[!solr?&fabricant_facet=`[[*pagetitle]]`& product_type =`[[+thisParent]]`&rows=`500`]]

    [[+thisParent]] is the result of a previously launched snippet (of course putting it in my template give the expected value)
    the actual query is fabricant_facet='' + product_type='' (empty)

    The is into a chunk used by the page tpl.
    Why the H* commonly used modx tag can't be populated ?!???


    Thank you for any clue to help us.

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      Make sure the snippet that sets the +thisParent placeholder is above the solr snippet tag on the page.

      It sounds like you're nesting pretty deeply there, which is always risky.

      You could try something like this. If it works it would I think it would be faster.

      Replace your solr tag with this:

      [[!ShowSolr]]
      


      Then create a snippet called ShowSolr with this code:

      /* ShowSolr Snippet */
      
      $doc = $modx->resource;
      $thisParent = '##'; // Set this here. maybe borrowing the code from the other snippet
                          // that used to set the placeholder
      $fields = array(
          'fabricant_facet' => $doc->get('pagetitle'),
          'product_type' => $thisParent,
          'rows' => `500`,
      );
      
      return $modx->runSnippet('solr', $fields);
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 36604
        • 268 Posts
        Hi!

        Looks like you pointed it...
        We are in the magic area where coding is no more an exact science.

        So I reintegrated my GetPArents snippet into your code, and add the rows as parameters.
        Looks like this solves by unknown means the issue...

        Thanks a lot!

        Quote from: BobRay at Jun 02, 2017, 04:37 PM
        Make sure the snippet that sets the +thisParent placeholder is above the solr snippet tag on the page.

        It sounds like you're nesting pretty deeply there, which is always risky.

        You could try something like this. If it works it would I think it would be faster.

        Replace your solr tag with this:

        [[!ShowSolr]]
        


        Then create a snippet called ShowSolr with this code:

        <?php
        /* ShowSolr
         Snippet */
        // on récupère $rows comme paramètre passé à cette fction
        
        $doc = $modx->resource;
        
        $id = $modx->resource->get('id'); 
        $parentsIds = $modx->getParentIds($id, 2); 
        $thisParentID = $parentsIds[0];
        /* Get the parent object */
        $thisParentObj = $modx->getObject('modResource', $thisParentID);
        /* If we have the parent,
           get and return the pagetitle */
        if ($thisParentObj) {
            $output = $thisParentObj->get('pagetitle');
        	$thisParent = $output;
            $modx->setPlaceholder('thisParent',$output);
        }
        $thisGDParent = $parentsIds[1];
        $thisGDParentObj = $modx->getObject('modResource', $thisGDParent);
        if ($thisGDParentObj) {
            $output = $thisGDParentObj->get('pagetitle');
            $modx->setPlaceholder('thisGDParent',$output);
        }
        
        
        // $thisParent = '##';  Set this here. maybe borrowing the code from the other snippet
                            // that used to set the placeholder
        $fields = array(
            'fabricant_facet' => $doc->get('pagetitle'),
            'product_type' => $thisParent,
        	'rows' => $rows,
        	//'rows' => `$rows`,
        );
        
        return $modx->runSnippet('solr', $fields);
          • 3749
          • 24,544 Posts
          We are in the magic area where coding is no more an exact science.

          It's still an exact science, imo, but deep nesting makes it very difficult to understand the scientific laws that apply. wink

          You might be interested in this article from my Blog: https://bobsguides.com/blog.html/2014/05/15/dont-be-a-nester/.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting