4

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    }

1 Answer 1

2

The onPrepareFinderContent method is mainly useful though if you're trying to manipulate other record types (i.e. from your plugin you want to add some extra data to com_content articles). If you're just adding data to your own object type, add whatever data to the $item object directly in your index() method.

In the case of your hierarchical data, I'd suggest studying the core Finder plugins for com_content and com_categories and using them to help sort through what you're trying to accomplish. A hint if I remember things correctly, you'd want to use the addTaxonomy methods to help with this.

3
  • i appreciate your thoughts...I'm still confused about how to "join" children records..you say "add whatever data to the $item object in the index method", but I can't see how to add say, 5 chapters to each title when the title is being index. It's not just a field i'm adding, it's 5 related records for that title.
    – GDP
    Commented Jan 27, 2016 at 19:14
  • You'd add data using taxonomy. There isn't a way to explicitly join records in the way I think you're trying to get at. That's how core com_content tells Finder that an article is assigned to a specific category.
    – Michael
    Commented Jan 27, 2016 at 21:04
  • I truly appreciate your comments, but it doesn't help any more than the few docs that exist..."using taxonomy" I'm afraid I might abandon my great hope of exploiting com_finder as nobody seems to have done it before or are keeping a grand secret from the internet.
    – GDP
    Commented Jan 28, 2016 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.