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