I've read google all the very limited documention of SmartSearch/com_finder routines after starting with How to add com_content extra fields to Smart Search Index, and am no further along understanding how to extend the indexing to additional fields in Smart Search than when I started :(
Essentially, I have "Titles", that have n children Programs, each of which have n Chapters. Each of these have content that I must index such that they point back to the parent Title that they are part of.
TitleA (tTitle,tBody,tSummary)
- ProgramA1 (pTitle,pBody,pSummary)
- ChapterA1a (cTitle,cBody,cSummary)
- ChapterA1b
- ProgramA2
TitleB
- ProgramB1
I've cloned the examples that are included in J3, and have the top level "Title" indexing working just as it should be, however, even after reading what little there is about extending it, I can't figure out how to incorporate the lower level content. The above mentioned question has an answer to fork/modify the standard routines, and another that talks about using addinstruction()
. The OP comments that he/she wrote a plugin, but with no specifics and no followup on the question itself.
I know this question approaches "doing the code" for me, but I'm at a loss with the implied knowledge that seems to be required, and lack of reference material to understand how to make this work.
So, the question itself: At line 24 below, FinderIndexerHelper::getContentExtras($item)
is the apparent place to link the lower levels of content. That routine (in the helper) simply says "Method to get extra data for a content before being indexed. This is how we add Comments, Tags, Labels, etc. that should be available to Finder.", then triggers another event onPrepareFinderContent
. I can't find anywhere that this function or event is used, or any indication of where to use SQL to get/link the data I'm interested in. Does anyone have any experience with this method/event that can give me a clear example of how to use them with the hierarchy of the given content?
01 class plgFinderAbc_Titles extends FinderIndexerAdapter
02 {
03 protected $context = 'ABC_TITLES';
04 protected $extension = 'com_abc';
05 protected $layout = 'myFinderLayout';
06 protected $type_title = 'ABC_FINDER_TPC_TITLES';
07 protected $table = '#__abc_titles';
08 public function __construct(&$subject, $config) {
09 parent::__construct($subject, $config);
10 $this->loadLanguage();
11 }
12 public function index(FinderIndexerResult $item, $format = 'html') {
13 $db = JFactory::getDbo();
14 $item->body = FinderIndexerHelper::prepareContent($item->getElement('tBody'));
15 $item->summary = FinderIndexerHelper::prepareContent($item->getElement('tSummary'));
16 $item->addTaxonomy('Type', 'ABC_FINDER_TITLE');
17 $item->url = 'index.php?option=com_abc&id=' . $item->getElement('tid');
18 $item->route = $item->url;
19 $item->state = $item->getElement('pub');
20 $item->access = 1;
21 $item->addInstruction(FinderIndexer::META_CONTEXT, 'tMetadesc');
22
23 // Get content extras. ???????????????
24 FinderIndexerHelper::getContentExtras($item);
25 // Index the item.
26 $this->indexer->index($item);
27 }
28 protected function setup() {
29 return true;
30 }
31 protected function getListQuery($sql = null) {
32 $db = JFactory::getDbo();
33 $sql = $sql instanceof JDatabaseQuery ? $sql : $db->getQuery(true);
34 $sql->select('id as tid, title as title, shortdesc as tSummary, fulldesc as tBody, as tMetadesc');$sql->from('#__tpc_titles AS a')->where('state = 1');
35 return $sql;
36 }
37 }