Full text query in joomla

How I do a full-text search query with joomla objects. I tried but did not work

$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 displays the template configuration parameters

+4
source share
2 answers

Your table should be configured using ENGINE = MyISAM (not InnoDB), and the columns you are looking for should be set to FULLTEXT.

You can easily set the table in MyISAM in phpMyAdmin through the "SQL" tab ...

 ALTER TABLE `tablename` ENGINE=MYISAM; 

In Joomla 2.5+ (probably 3+ as well) in my request as a where clause, which I used ...

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

Further testing is fine, but so far it is working as expected.

+1
source

The $ request inside the where clause seems odd to me.

-2
source

Source: https://habr.com/ru/post/1494141/


All Articles