Skip to content

Commit

Permalink
Change Autosuggester so that it respects
Browse files Browse the repository at this point in the history
static-filters,accesslevels,publish up/down dates and article states
  • Loading branch information
tkempf committed Mar 10, 2015
1 parent edcd858 commit 0c0f96d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 9 deletions.
103 changes: 96 additions & 7 deletions components/com_finder/models/suggestions.php
Expand Up @@ -59,17 +59,106 @@ protected function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
//attempt to change mysql for error in large select
$db->setQuery('SET SQL_BIG_SELECTS=1');
$db->query();

$query = $db->getQuery(true);

// Set variables
$user = JFactory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$app = JFactory::getApplication();
$input = $app->input;
$request = $input->request;

// Select required fields
$query->select('t.term')
->from($db->quoteName('#__finder_terms') . ' AS t')
->where('t.term LIKE ' . $db->quote($db->escape($this->getState('input'), true) . '%'))
->where('t.common = 0')
->where('t.language IN (' . $db->quote($db->escape($this->getState('language'), true)) . ', ' . $db->quote('*') . ')')
->order('t.links DESC')
->order('t.weight DESC');
$query->select('t.term');
$query->from($db->quoteName('#__finder_terms') . ' AS t');
$query->where('t.term LIKE ' . $db->quote($db->escape($this->getState('input'), true) . '%'));
$query->where('t.common = 0');
$query->order('t.links DESC');
$query->order('t.weight DESC');
$linkjoin='';

// Iterate through each term mapping table and add the join.
for ($i = 0; $i < 16; $i++)
{
// We use the offset because each join needs a unique alias.
$query->join('LEFT', $db->quoteName('#__finder_links_terms'.dechex($i)) . ' AS lterms'. $i .' ON lterms'. $i .'.term_id = t.term_id');
$linkjoin.='lterms'.$i.'.link_id=l.link_id';
if($i<15)
$linkjoin.=' or ';
}
$query->join('INNER',$db->quoteName('#__finder_links') . ' AS l ON ('.$linkjoin.')');

$query->where($db->quoteName('l.access') . ' IN (' . $groups . ')');
$query->where($db->quoteName('l.state') . ' = 1');

// Get the null date and the current date, minus seconds.
$nullDate = $db->quote($db->getNullDate());
$nowDate = $db->quote(substr_replace(JFactory::getDate()->toSQL(), '00', -2));

// Add the publish up and publish down filters.
$query->where('(' . $db->quoteName('l.publish_start_date') . ' = ' . $nullDate . ' OR ' . $db->quoteName('l.publish_start_date') . ' <= ' . $nowDate . ')');
$query->where('(' . $db->quoteName('l.publish_end_date') . ' = ' . $nullDate . ' OR ' . $db->quoteName('l.publish_end_date') . ' >= ' . $nowDate . ')');


if (!is_null($request->get('f')))
{
$query->join('INNER',$db->quoteName('#__finder_taxonomy_map') . ' AS tm ON (tm.link_id=l.link_id)');
$query->join('INNER',$db->quoteName('#__finder_filters') . ' AS ff ON (ff.data=tm.node_id)');
$query->where($db->quoteName('ff.filter_id') . ' = '.$request->get('f','','int'));

}
/*
* Didn't know what these do, so i commented them out
*
// Add the start date filter to the query.
if (!empty($this->query->date1))
{
// Escape the date.
$date1 = $db->quote($this->query->date1);
// Add the appropriate WHERE condition.
if ($this->query->when1 == 'before')
{
$query->where($db->quoteName('l.start_date') . ' <= ' . $date1);
}
elseif ($this->query->when1 == 'after')
{
$query->where($db->quoteName('l.start_date') . ' >= ' . $date1);
}
else
{
$query->where($db->quoteName('l.start_date') . ' = ' . $date1);
}
}
// Add the end date filter to the query.
if (!empty($this->query->date2))
{
// Escape the date.
$date2 = $db->quote($this->query->date2);
// Add the appropriate WHERE condition.
if ($this->query->when2 == 'before')
{
$query->where($db->quoteName('l.start_date') . ' <= ' . $date2);
}
elseif ($this->query->when2 == 'after')
{
$query->where($db->quoteName('l.start_date') . ' >= ' . $date2);
}
else
{
$query->where($db->quoteName('l.start_date') . ' = ' . $date2);
}
}
*/
// Filter by language
if ($this->getState('filter.language')) {
$query->where('l.language in ('.$db->quote(JFactory::getLanguage()->getTag()).','.$db->quote('*').')');
}
return $query;
}

Expand Down
2 changes: 1 addition & 1 deletion components/com_finder/views/search/tmpl/default_form.php
Expand Up @@ -42,7 +42,7 @@

$script .= "
var suggest = jQuery('#q').autocomplete({
serviceUrl: '" . JRoute::_('index.php?option=com_finder&task=suggestions.suggest&format=json&tmpl=component', false) . "',
serviceUrl: '" . JRoute::_('index.php?option=com_finder&task=suggestions.suggest&format=json&tmpl=component&f='.$params->get('searchfilter'), false) . "',
paramName: 'q',
minChars: 1,
maxHeight: 400,
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_finder/tmpl/default.php
Expand Up @@ -128,7 +128,7 @@

$script .= "
var suggest = jQuery('#mod-finder-searchword').autocomplete({
serviceUrl: '" . JRoute::_('index.php?option=com_finder&task=suggestions.suggest&format=json&tmpl=component', false) . "',
serviceUrl: '" . JRoute::_('index.php?option=com_finder&task=suggestions.suggest&format=json&tmpl=component&f='.$params->get('searchfilter'), false) . "',
paramName: 'q',
minChars: 1,
maxHeight: 400,
Expand Down

0 comments on commit 0c0f96d

Please sign in to comment.