/** * Create the query that would be issued for the given search for the complete keys. * * @param SearchApiAutocompleteSearch $search * The search for which to create the query. * @param $complete * A string containing the complete search keys. * @param $incomplete * A string containing the incomplete last search key. * * @return SearchApiQueryInterface * The query that would normally be executed when only $complete was entered * as the search keys for the given search. */ function example_create_autocomplete_query(SearchApiAutocompleteSearch $search, $complete, $incomplete) { $query = search_api_query($search->index_id); if ($complete) { $query->keys($complete); } if (!empty($search->options['custom']['extra'])) { list($f, $v) = explode('=', $search->options['custom']['extra'], 2); $query->condition($f, $v); } if (!empty($search->options['custom']['user_filters'])) { foreach (explode("\n", $search->options['custom']['user_filters']) as $line) { list($f, $v) = explode('=', $line, 2); $query->condition($f, $v); } } return $query; }
/** * Returns RSS data for discussions. */ public function getDiscussionsRSSData() { $cache_name = implode(':', array(__FUNCTION__, $this->node->nid)); $cache = cache_get($cache_name); if ($cache && time() < $cache->expire) { $results = $cache->data; } else { global $language; $build_date = time(); $nids_query = search_api_query('default_node_index', array('languages' => array($language->language))); $filter = $nids_query->createFilter(); $filter->condition('og_group_ref', $this->node->nid); $filter->condition('type', 'discussion'); $nids_query->filter($filter); $nids_query->sort('changed', 'DESC'); $nids_results = $nids_query->execute(); if (!isset($nids_results['results']) || !count($nids_results['results'])) { return array(array(), REQUEST_TIME); } $nids = array_keys($nids_results['results']); $query = $this->getRSSBasicQuery($nids); $results = $query->execute()->fetchAllAssoc('nid'); global $base_root; // Using the items selected in the query, we compute some other fields // that should be exported to the templates. foreach ($results as $nid => &$result) { $result->url = $base_root . '/' . drupal_get_path_alias('node/' . $nid); $result->guid = $base_root . '/node/' . $nid; $result->pubDate = format_date($result->created, 'custom', 'D, d M Y H:i:s O'); $result->description = $this->rssSummaryOrTrimmed($result->body_value, $result->body_summary); } cache_set($cache_name, $results, 'cache', time() + 60); } return array($results, isset($cache->created) ? $cache->created : REQUEST_TIME); }