• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
  • This forum is for release discussion only. Discussions that do not relate specifically to the resource release should be discussed in another, more appropriate forum.
  • This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Disable search caching

Jake Bunce

XenForo moderator
Staff member
#1
(in response to this post)

This is a code modification that will disable search caching. In other words, every time you submit a search it will perform a brand new search and not look at previous results. This has potential to increase server load on busy forums, but it will ensure that search results are always current.

Edit this file:

library/XenForo/Model/Search.php

Find this code and add the red code:

Code:
	public function getExistingSearch($searchType, $searchQuery, array $constraints, $order, $groupByDiscussion, $userId, $forceUsage = false)
	{
		return false;

		if (XenForo_Application::debugMode() && !$forceUsage)
		{
			return false;
		}

		$queryHash = $this->getSearchQueryHash($searchType, $searchQuery, $constraints, $order, $groupByDiscussion);

		return $this->_getDb()->fetchRow('
			SELECT *
			FROM xf_search
			WHERE query_hash = ?
				AND search_type = ?
				AND search_query = ?
				AND user_id = ?
				AND search_date > ?
			ORDER BY search_date DESC
			LIMIT 1
		', array($queryHash, $searchType, $searchQuery, $userId, XenForo_Application::$time - 3600));
	}
Note that the cache will still be employed if you link directly to the search results. You need to submit a new search if you want fresh results. You can use a URL to submit a new search if you want. Use this format:

index.php?search/search/&keywords=term