3

Is it possible to call the Smart Search "engine" from a custom component, hopefully with AJAX?

Our component has an exhaustive amount of content that needs to be searched from within the component itself, and I'd like to leverage the "smarts" of com_finder without having to start at the the com_finder default page.

I've tried CURL and AJAX, but all I've been able to retrieve is the full page that com_finder would normally render.

2

I'm still interested in a better answer since this solution tinkers with the core installation, but I added the below file to get what I needed, with the following examples:

  • index.php?option=com_finder&view=search&format=json&q=%22my+searched+phrase%22
  • index.php?option=com_finder&view=search&format=json&q=my+keywords+to+find
  • index.php?option=com_finder&view=search&format=json&q=my+keywords+to+find&limit=10

components\com_finder\views\search\view.json.php

<?php
defined('_JEXEC') or die;
/**
* Search json view class for the Finder package.
*/
class FinderViewSearch extends JViewLegacy
{
    public function display($tpl = null)
    {
        // Get the application
        $app = JFactory::getApplication();
        JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');

        // Get view data.
        $state = $this->get('State');
        $query = $this->get('Query');
        $results = $this->get('Results');

        // Push out the query data.
        if (empty($results))
            $results = array();
        $data['results']        = $results;
        $data['explained_html'] = JHtml::_('query.explained', $query);
        $data['explained']      = strip_tags($data['explained_html']);
        $data['params']         = $state->get('params');
        $data['query']          = $this->get('Query');

        header('Content-Type: application/json');
        $response = new JResponseJson($data, 'Search returned '.count($results).' results' ,false);
        echo $response;
        $app->close();
    }
}
| improve this answer | |
  • If it's for a single client site, it's actually ok since it's upgrade friendly solution, you didn't change any core file – Marko D Oct 25 '15 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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