joomla中的全文查询(fulltext query in joomla)

18 IT屋

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

解决方案

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.

如何对joomla对象进行全文搜索。我一直在尝试,但是没有用



  $ 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()){
抛出new Exception($ db-> getErrorMsg());
}

$ data = $ db-> loadObjectList();

var_dump($ query);


结果输出模板配置参数


解决方案

必须使用ENGINE = MyISAM(不是InnoDB)设置表,并且要搜索的列必须设置为FULLTEXT索引。



您可以通过" SQL"选项卡在phpMyAdmin中轻松地将表设置为MyISAM ...



  ALTER TABLE`tablename ENGINE = MYISAM; 


在Joomla 2.5+(可能也是3+)中,我使用where子句。 ..



 ->其中('MATCH('。$ db-" quoteName('columnname')。')反对('。$ db-" quote($ words_or_phrase_to_search_for)。')'); 


还可以进行进一步的测试,但到目前为止,它似乎按预期运行。


本文地址:IT屋 » joomla中的全文查询