We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45118
    • 123 Posts
    Our website has product pages that get created dynamically. All the information is in a database; item numbers, dimensions, descriptions etc. I installed SimpleSearch but I can't get it to look into the database, so searching for a specific item number gives no result. I've tried something like this
    &customPackages=`products:name:ourproducts:core/components/ourproducts/model/:products.resource = modresource.42`
    but I seem to be doing it wrong.

    Any ideas?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      In order to use SimpleSearch to search custom tables you must have a proper MODX package for it, with the schema files and everything.

      https://rtfm.modx.com/extras/revo/simplesearch/simplesearch.simplesearch#SimpleSearch.SimpleSearch-SearchingCustomTables

      You might be able to use a Faceted Search post-hook with your post-hook querying your custom table with a more direct query.

      https://rtfm.modx.com/extras/revo/simplesearch/simplesearch.simplesearch/simplesearch.faceted-search-through-posthooks
        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
        • 45118
        • 123 Posts
        Hi Susan,

        Yes, I have a proper package for it, or at least I think it is wink
        className: bbproducts
        fieldName: aei
        packageName: aeibbproducts
        packagePath: core/components/aeibbproducts/model/
        joinCriteria: bbproducts.resource = modresource.42
        &customPackages=`bbproducts:aei:aeibbproducts:core/components/aeibbproducts/model/:bbproducts.resource = modresource.42`

        42 is the search landing page but I'm not sure if I understand "joinCriteria" correctly.

        This is how it appears on the landing page:
        [[!SimpleSearch? &customPackages=`bbproducts:aei:aeibbproducts:core/components/aeibbproducts/model/:bbproducts.resource = modresource.42`]]
          • 45118
          • 123 Posts
          I've tested the &customPackages property and checked the error log. The format is (according to https://rtfm.modx.com/extras/revo/simplesearch/simplesearch.simplesearch) as follows
          className:fieldName(s):packageName:packagePath:joinCriteria

          The search results page has this tag:
          [[!SimpleSearch? &customPackages=`bbproducts:aei:aei_bbproducts:core/components/aeibbproducts/model/:bbproducts.resource = modresource.42`]]
          and this is the error from the log:

          [2015-09-25 17:19:21] (ERROR @ /index.php) Could not load class: bbproducts from mysql.bbproducts.
          [2015-09-25 17:19:21] (ERROR @ /index.php) Error 42S22 executing statement:
          Array
          (
          [0] => 42S22
          [1] => 1054
          [2] => Unknown column 'bbproducts.aei' in 'where clause'
          )

          Can anyone help me figure out what this means?
            • 4172
            • 5,888 Posts
            whats your xml-schema?
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 45118
              • 123 Posts
              I've also tried "Faceted Search Through PostHooks". The problem is that I get two sets of results on the results page.
              When I search for a word that appears in the content, I get two identical lists underneath each other.
              When I search for an item no (where the item no doesn't appear in the content but it is in the database) the results page shows this:
              There were no search results for the search
              "ABC123456". Please try using more general terms to
              get more results.
              1. ABC123456

              So now I know it can search the database but the double search results are confusing. Is there a way to not show the first result when there's an item no result?

              Here's my SearchForm call
              [[!SimpleSearchForm? &tpl=`MySearchForm` &landing=`42`]]

              On the Search Results page
              [[!SimpleSearch? &postHooks=`ItemnoFacetHook` &tplitemno=`MySearchResult`]]
              
              [[+sisea.results]]
              <br /><br />
              [[+sisea.itemno.results]]

              ItemnoFacetHook snippet
              <?php
              $path = MODX_CORE_PATH . 'components/aeibbproducts/';
              $result = $modx->addPackage('aeibbproducts',$path .
                  'model/','aei_');
              
              if (! $result) {
                  return 'failed to add package';
              }
              
              $c = $modx->newQuery('BbProducts');
              $c->where(array('aei' => $search));
              
              $product = $modx->getObject('BbProducts', $c);
              $results = array();
              if ($product) {
                  $results[] = array(
                      'pagetitle' => $product->get('aei'),
                      'longtitle' => $product->get('sim')
                  );
              }
              
              $hook->addFacet('itemno',$results);
              return true;

              MySearchForm chunk
              <form class="sisea-search-form" action="[[~[[+landing]]]]" method="[[+method]]">
                <fieldset>
              
                  <input type="text" name="[[+searchIndex]]" id="[[+searchIndex]]" value="[[+searchValue]]" />
                  <input type="hidden" name="id" value="[[+landing]]" /> 
              
                  <input type="submit" value="[[%sisea.search? &namespace=`sisea` &topic=`default`]]" />
                </fieldset>
              </form>

              MySearchResult chunk
              <div class="sisea-result">
                  <h3>[[+idx]]. <a href="[[~30? &prodNum=`[[+pagetitle]]` &simCode=`[[+longtitle]]`]]" title="[[+pagetitle]]">[[+pagetitle]]</a></h3>
              </div>


              Thanks in advance for all the help!
                • 45118
                • 123 Posts
                Quote from: Bruno17 at Sep 25, 2015, 01:49 PM
                whats your xml-schema?
                It is
                <?xml version="1.0" encoding="UTF-8"?>
                <model package="aeibbproducts" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
                	<object class="BbProducts" table="bb_products" extends="xPDOObject">
                		<field key="aei" dbtype="varchar" precision="16" phptype="string" null="false" default="" index="pk" />
                		<field key="pre" dbtype="char" precision="3" phptype="string" null="false" />
                		<field key="suff" dbtype="varchar" precision="6" phptype="string" null="true" />
                		<field key="des1" dbtype="varchar" precision="30" phptype="string" null="false" />
                		<field key="des2" dbtype="varchar" precision="30" phptype="string" null="true" />
                		<field key="des3" dbtype="varchar" precision="30" phptype="string" null="true" />
                		<field key="width" dbtype="decimal" precision="7,5" phptype="float" null="true" />
                		<field key="height" dbtype="decimal" precision="7,5" phptype="float" null="true" />
                		<field key="proj" dbtype="decimal" precision="7,5" phptype="float" null="true" />
                		<field key="pitch" dbtype="varchar" precision="10" phptype="string" null="true" />
                		<field key="fin" dbtype="varchar" precision="40" phptype="string" null="true" />
                		<field key="mtl" dbtype="varchar" precision="20" phptype="string" null="true" />
                		<field key="sim" dbtype="varchar" precision="6" phptype="string" null="true" />
                
                		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
                			<column key="aei" length="" collation="A" null="false" />
                		</index>
                	</object>
                </model>
                  • 4172
                  • 5,888 Posts
                  your class is

                  BbProducts

                  not

                  bbproducts

                  you wrote

                  &customPackages=`bbproducts:aei:
                  


                  but has to be

                  &customPackages=`BbProducts:aei:

                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 45118
                    • 123 Posts
                    Quote from: Bruno17 at Sep 25, 2015, 02:35 PM
                    your class is

                    BbProducts

                    not

                    bbproducts

                    you wrote

                    &customPackages=`bbproducts:aei:
                    


                    but has to be

                    &customPackages=`BbProducts:aei:

                    Hi Bruno,
                    I tried the tag with the change
                    [[!SimpleSearch? &customPackages=`Bbproducts:aei:aei_bbproducts:core/components/aeibbproducts/model/:bbproducts.resource = modresource.42`]]

                    And this is the error in the log:

                    [2015-09-26 15:54:32] (ERROR @ /index.php) Could not load class: Bbproducts from mysql.bbproducts.
                    [2015-09-26 15:54:32] (ERROR @ /index.php) Error 42S22 executing statement:
                    Array
                    (
                    [0] => 42S22
                    [1] => 1054
                    [2] => Unknown column 'Bbproducts.aei' in 'where clause'
                    )

                    I've tried a few other changes but all with a similar result. Hopefully you have some more ideas for me smiley !
                      • 4172
                      • 5,888 Posts
                      your packageName is aeibbproducts, not aei_bbproducts
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!