fulltext query in joomla

安稳与你 提交于 2019-12-10 18:16:55

问题


How do I buld a fulltext search query with joomla objects. I have been trying but it's not working

   $db = JFactory::getDBO();
        $query = $db->getQuery(true);
        $query->select('*');
        $query->from('#__unis_subjects AS s');
        $query->join('', '#__unis AS u ON s.university = u.id');
        $query->join('', '#__unis_faculties AS f ON f.id = s.faculty');
        $query->where('MATCH (s.subject) AGAINST ("' . $query . '")');

        if (!$db->query()) {
            throw new Exception($db->getErrorMsg());
        }

        $data = $db->loadObjectList();

        var_dump($query);

the result outputs template config parameters


回答1:


Your table must be set up using ENGINE = MyISAM (not InnoDB) and the columns you're searching must be set to FULLTEXT indexing.

You can easily set your table to MyISAM in phpMyAdmin via the 'SQL' tab...

ALTER TABLE `tablename` ENGINE=MYISAM;

In Joomla 2.5+ (likely 3+ as well) in my query as a where clause I used...

->where('MATCH ('.$db->quoteName('columnname').') AGAINST ('.$db->quote($words_or_phrase_to_search_for).')');

Further testing is in order but so far it seems to be working as expected.




回答2:


The $query inside the where condition seems strange to me.



来源:https://stackoverflow.com/questions/17933830/fulltext-query-in-joomla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!