问题
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