diff --git a/components/com_finder/models/suggestions.php b/components/com_finder/models/suggestions.php index 915d8fb827dd7..0e300dedf9dda 100644 --- a/components/com_finder/models/suggestions.php +++ b/components/com_finder/models/suggestions.php @@ -59,8 +59,30 @@ protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); + if (in_array($db->name, array('mysqli', 'mysql'))) + { + // Attempt to change mysql for error in large select + $db->setQuery('SET SQL_BIG_SELECTS=1'); + $db->query(); + } $query = $db->getQuery(true); + // Get the static Taxonomy filter parameters if necessary + if (!is_null($this->getState('filter'))) + { + // Select filter params + $query->select('ff.params') + ->from($db->quoteName('#__finder_filters') . ' AS ff') + ->where('ff.filter_id = ' . $this->getState('filter')); + $db->setQuery($query); + $filterparams = json_decode($db->loadResult()); + + // Get a fresh query object + $query = $db->getQuery(true); + } + + $groups = implode(',', $this->getState('user.groups')); + // Select required fields $query->select('t.term') ->from($db->quoteName('#__finder_terms') . ' AS t') @@ -70,6 +92,84 @@ protected function getListQuery() ->order('t.links DESC') ->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 . ')') + ->where('l.access IN (' . $groups . ')') + ->where('l.state = 1') + ->where('l.published = 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('(l.publish_start_date = ' . $nullDate . ' OR l.publish_start_date <= ' . $nowDate . ')') + ->where('(l.publish_end_date = ' . $nullDate . ' OR l.publish_end_date >= ' . $nowDate . ')'); + + // Add the static Taxonomy filter if necessary + if (!is_null($this->getState('filter'))) + { + // Add the static Taxonomy filter + $query->join('INNER', $db->quoteName('#__finder_taxonomy_map') . ' AS tm ON (tm.link_id=l.link_id)') + ->join('INNER', $db->quoteName('#__finder_filters') . ' AS ff ON (ff.data=tm.node_id)') + ->where('ff.filter_id = ' . $this->getState('filter')); + + // Add the start date filter to the query. + if ($filterparams->w1 != '') + { + // Escape the date. + $date1 = $db->quote($filterparams->d1); + + // Add the appropriate WHERE condition. + if ($filterparams->w1 == -1) + { + $query->where($db->quoteName('l.start_date') . ' <= ' . $date1); + } + elseif ($filterparams->w1 == 1) + { + $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 ($filterparams->w2 != '') + { + // Escape the date. + $date2 = $db->quote($filterparams->d2); + + // Add the appropriate WHERE condition. + if ($filterparams->w2 == -1) + { + $query->where($db->quoteName('l.start_date') . ' <= ' . $date2); + } + elseif ($filterparams->w2 == 1) + { + $query->where($db->quoteName('l.start_date') . ' >= ' . $date2); + } + else + { + $query->where($db->quoteName('l.start_date') . ' = ' . $date2); + } + } + + } + return $query; } @@ -133,6 +233,9 @@ protected function populateState($ordering = null, $direction = null) $lang = FinderIndexerHelper::getPrimaryLanguage($lang); $this->setState('language', $lang); + // Get the static taxonomy filter. + $this->setState('filter', $input->request->get('f', '', 'int')); + // Load the list state. $this->setState('list.start', 0); $this->setState('list.limit', 10); @@ -142,5 +245,7 @@ protected function populateState($ordering = null, $direction = null) // Load the user state. $this->setState('user.id', (int) $user->get('id')); + $this->setState('user.groups', $user->getAuthorisedViewLevels()); + } } diff --git a/components/com_finder/views/search/tmpl/default_form.php b/components/com_finder/views/search/tmpl/default_form.php index d2dc92d5bd0af..f093f9b15b980 100644 --- a/components/com_finder/views/search/tmpl/default_form.php +++ b/components/com_finder/views/search/tmpl/default_form.php @@ -39,10 +39,11 @@ if ($this->params->get('show_autosuggest', 1)) { JHtml::_('script', 'media/jui/js/jquery.autocomplete.min.js', false, false, false, false, true); + $filter = ($this->params->get('searchfilter') != '') ? '&f=' . $this->params->get('searchfilter') : ''; $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' . $filter, false) . "', paramName: 'q', minChars: 1, maxHeight: 400, diff --git a/modules/mod_finder/tmpl/default.php b/modules/mod_finder/tmpl/default.php index 8c0fd11a57c15..2c18d68631148 100644 --- a/modules/mod_finder/tmpl/default.php +++ b/modules/mod_finder/tmpl/default.php @@ -125,10 +125,11 @@ if ($params->get('show_autosuggest', 1)) { JHtml::_('script', 'media/jui/js/jquery.autocomplete.min.js', false, false, false, false, true); + $filter = ($params->get('searchfilter') != '') ? '&f=' . $params->get('searchfilter') : ''; $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' . $filter, false) . "', paramName: 'q', minChars: 1, maxHeight: 400,