protected function process_sort(vB_Search_Criteria &$criteria) { $sort_array = $criteria->get_sort(); $this->sort = array(); $sort_map = array('user' => 'authorname', 'author' => 'authorname', 'publishdate' => 'publishdate', 'created' => 'created', 'started' => 'created', 'last_post' => 'lastcontent', 'lastcontent' => 'lastcontent', 'textcount' => 'textcount', 'replies' => 'textcount', 'displayorder' => 'displayorder', 'rank' => 'rank', 'relevance' => 'rank', 'votes' => 'votes'); foreach ($sort_array as $sort => $direction) { $direction = strtoupper($direction); if (!in_array($direction, array('ASC', 'DESC'))) { $direction = 'ASC'; } // if we don't have a sort, or we have an unrecognized sort type default to relevance descending if (!$sort or !isset($sort_map[$sort])) { $sort = 'relevance'; $direction = 'DESC'; } //look for a core sort option if (isset($sort_map[$sort])) { $sort_field = $sort_map[$sort]; // process rank sortings if ($sort_field == 'rank') { $this->what[] = "weight() as rank"; } else { $sort_field = "{$sort_field}"; } $this->sort[] = $sort_field . ' ' . $direction; } } }
protected function process_sort(vB_Search_Criteria &$criteria) { $sort_array = $criteria->get_sort(); $this->sort = array(); $sort_map = array('user' => 'authorname', 'author' => 'authorname', 'publishdate' => 'publishdate', 'created' => 'created', 'started' => 'created', 'last_post' => 'lastcontent', 'lastcontent' => 'lastcontent', 'title' => 'title', 'textcount' => 'textcount', 'replies' => 'textcount', 'displayorder' => 'displayorder', 'rank' => 'score', 'relevance' => 'score', 'votes' => 'votes'); foreach ($sort_array as $sort => $direction) { $direction = strtoupper($direction); if (!in_array($direction, array('ASC', 'DESC'))) { $direction = 'ASC'; } // use the starter's title if ($sort == 'title') { $this->join['starter'] = "LEFT JOIN " . TABLE_PREFIX . "node AS starter ON starter.nodeid = IF(node.starter = 0, node.nodeid, node.starter)"; $this->sort['starter.title'] = $direction; continue; } // if we don't have a sort, or we have an unrecognized sort type default to relevance descending if (!$sort or !isset($sort_map[$sort])) { $sort = 'relevance'; $direction = 'DESC'; } //look for a core sort option if (isset($sort_map[$sort])) { $sort_field = $sort_map[$sort]; // process rank sortings if ($sort_field == 'score') { $sort_field = 'rank'; } else { $sort_field = "node.{$sort_field}"; } $this->sort[$sort_field] = $direction; } } }
public function getFromCache(vB_Search_Criteria $criteria, $search_json) { $cacheTTL = vB_Api_Search::getCacheTTL(); if ($cacheTTL == 0) { return false; } $hashkey = $this->generateHash($criteria->getJSON()); //now see if we have a cached value. $hashes = array($hashkey); if (!empty($search_json['custom'])) { $hashes[] = $customhashkey = $this->generateHash($search_json); } $conditions = array(array('field' => 'searchhash', 'value' => $hashes, 'operator' => vB_dB_Query::OPERATOR_EQ), array('field' => 'userid', 'value' => vB::getCurrentSession()->get('userid'), 'operator' => vB_dB_Query::OPERATOR_EQ), array('field' => 'dateline', 'value' => vB::getRequest()->getTimeNow() - vB_Api_Search::getCacheTTL() * 60, 'operator' => vB_dB_Query::OPERATOR_GTE)); $sort = $criteria->get_sort(); if (!empty($sort)) { $conditions[] = array('field' => 'sortby', 'value' => key($sort), 'operator' => vB_dB_Query::OPERATOR_EQ); $conditions[] = array('field' => 'sortorder', 'value' => current($sort), 'operator' => vB_dB_Query::OPERATOR_EQ); } $searchlogs = vB::getDbAssertor()->getRows('vBDbSearch:searchlog', array(vB_dB_Query::CONDITIONS_KEY => $conditions), array('field' => array('dateline'), 'direction' => vB_dB_Query::SORT_DESC), 'searchhash'); if (!empty($searchlogs[$hashkey])) { $searchlog = $searchlogs[$hashkey]; //Check the age cacheLife is minutes but the other values are seconds if ($searchlog['dateline'] - (vB::getRequest()->getTimeNow() - $cacheTTL * 60)) { return false; } $searchlog['resultId'] = $searchlog['searchlogid']; $searchlog['totalRecords'] = $searchlog['results_count']; $searchlog['from_cache'] = true; $ignored_words = $criteria->get_ignored_keywords(); if (!empty($ignored_words)) { $searchlog['ignored_keywords'] = $ignored_words; } // if there is a custom field we need to duplicate the search cache and save the custom field with it if (!empty($search_json['custom'])) { if (empty($searchlogs[$customhashkey])) { $customCriteria = $criteria; $customCriteria->setJSON($search_json); $customsearchlog = $this->cacheResults(explode(',', $searchlog['results']), $customCriteria, $searchlog['searchtime'], $searchlog['type']); $customsearchlog['totalRecords'] = $customsearchlog['results_count']; $customsearchlog['from_cache'] = true; $ignored_words = $customCriteria->get_ignored_keywords(); if (!empty($ignored_words)) { $customsearchlog['ignored_keywords'] = $ignored_words; } return $customsearchlog; } else { $customsearchlog = $searchlogs[$customhashkey]; $customsearchlog['resultId'] = $customsearchlog['searchlogid']; $customsearchlog['totalRecords'] = $customsearchlog['results_count']; $customsearchlog['from_cache'] = true; $ignored_words = $criteria->get_ignored_keywords(); if (!empty($ignored_words)) { $customsearchlog['ignored_keywords'] = $ignored_words; } return $customsearchlog; } } return $searchlog; } return false; }