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

    I’ve implemented SimpleSearch on my homepage and it works quite well on page resources. Now I tried to add the search of Quip comments. The wiki tells me how to do so:
    [[!SimpleSearch? &useAllWords=`1` &highlightTag=`em` &customPackages=`QuipComment:body:quip:{core_path}components/quip/model/:QuipComment.resource=modResource.id` ]]

    But now I have no results at all, even none of normal pages. Am I doing something wrong?

    Thanks!

    Franz
      • 34883
      • 7 Posts
      Ok I got one step further, the message log says:

      [2011-05-29 23:28:23] (ERROR @ /foo/index.php) Could not get table name for class: QuipComment
      [2011-05-29 23:28:23] (ERROR @ /foo/index.php) Error 42S02 executing statement: 
      Array
      (
          [0] => 42S02
          [1] => 1146
          [2] => Table 'foo.QuipComment' doesn't exist
      )


      So, can anyone tell me the correct class for the table modx_quip_comments? I tried QuipComments, quip_comments, modx_quip_comments, always resulting in the error log:
      [2011-05-29 23:27:38] (ERROR @ /foo/index.php) Could not load class: QuipComments from mysql.quipcomments.
      [2011-05-29 23:27:38] (ERROR @ /foo/index.php) Error 42S22 executing statement: 
      Array
      (
          [0] => 42S22
          [1] => 1054
          [2] => Unknown column 'QuipComments.body' in 'where clause'
      )

      Or is the problem somewhere else?

      I use simplesearch 1.4.0 and quip 2.0.4
        • 25979
        • 178 Posts
        Did you by any chance succeded?

        regards,

        mike
          //Why use windows since there is a door?//
          • 34883
          • 7 Posts
          No, I’m sorry. I haven’t had any time to experiment or have a look at the source.
            • 25979
            • 178 Posts
            So I will have to look into this myself, ’cause I need simpleSearch to search throgh images tags and descriptions in gallery.

            I will let know if I am to have any luck wink

            regards,

            mike
              //Why use windows since there is a door?//
              • 15734
              • 70 Posts
              Mike, Did you have any luck with simplesearch and gallery? Gotta do the same thing and it’s killing me.
                • 25979
                • 178 Posts
                Nope, no luck with that, but maybe advSearch from coroico will solve this problem smiley

                regards,

                mike
                  //Why use windows since there is a door?//
                • Hi,

                  I tried to make SimpleSearch search into other DB. The best (understand easiest) solution i found was to make use of the faceted search.

                  Hope this will help
                    • 25979
                    • 178 Posts
                    Hi, do you have an example how it is working for you?

                    regards,

                    mike
                      //Why use windows since there is a door?//
                      • 34883
                      • 7 Posts
                      OK guys, I finally got it.

                      Let’s begin with the result, the snippet code to search into comments (bodytext and author name) from Quip:

                      <?php
                      
                      // Searches the comments of quip for $search
                      
                      // We need to include the quip model
                      $quipPath = $modx->getOption('core_path').'components/quip/model/';
                      $modx->addPackage('quip',$quipPath);
                      
                      // Search in bodytext and author name
                      $c = $modx->newQuery('quipComment');
                      $c->where(array(
                          'body:LIKE' => '%'.$search.'%',
                          'OR:name:LIKE' => '%'.$search.'%'
                      ));
                      $count = $modx->getCount('quipComment',$c);
                      $c->select(array(
                          'id','body','name','createdon','resource'
                      ));
                      
                      $c->limit($limit,$offset);
                      $comments = $modx->getCollection('quipComment',$c);
                      
                      $results = array();
                      foreach ($comments as $comment) {
                        
                        // Extract text and add highlighting
                        // Use functions of the SimpleSearch class
                        $searchObj = new SimpleSearch($modx,array());
                        $searchObj->parseSearchString($search);
                        
                        $extract = $comment->get('body');
                        $extract = $searchObj->createExtract($extract, 200, $search,'…'); // number of chard and char to use for ellipsis 
                        $extract = preg_replace("#\[\[(.*?)\]\]#si", '', $extract); // cleanup extract
                        $extract = str_replace(array('[[',']]'), '', $extract);
                        $extract = $searchObj->addHighlighting($extract, 'sisea-highlight', 'em'); // highlighting class and tag
                           
                        $results[] = array(
                          	'id' => $comment->get('resource'),
                          	'pagetitle' => 'Kommentar von '. $comment->get('name'), // Comments from ...
                          	'longtitle' => 'Gehe zum Kommentar', // Go to comment
                          	'link' => $modx->makeUrl($comment->get('resource'),'','#qcom'. $comment->get('id')),
                          	'extract' => $extract
                          );
                      }
                      $hook->addFacet('comments',$results,$count);
                          
                      return true;


                      There are a number of thing I had to figure out:

                      1. If you search in plugin databases, you have to include the model of the plugin, so that modx knows the tables. Then you find the class name of the table (which you have to use) in the corresponding model file of the plugin.

                      2. The name for the extract in the associative array $result isn’t "excerpt" as in the example, but "extract"...

                      3. Th $result need an additional entry called "id" with the id of the landing page. (actually the number isn’t relevant if the linkk entry is set, but you would get errors in the error log)

                      I extended the example code. Now the result text is shortened and the search word highlighted. If you want to show up a text if there isn’t a result, use this code:
                      [[+sisea.comments.results:empty=`<p>Keine entsprechenden Kommentare gefunden.</p>`]]


                      I hope this is helpful for some of you smiley