1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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.
    Dismiss Notice
  3. 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

Discussion in 'Code Modifications [Archive]' started by Jake Bunce, Jul 30, 2011.

  1. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    (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:


    Find this code and add the red 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:

    MCTSS, black hawk, EQnoble and 2 others like this.
  2. Eliteoomph

    Eliteoomph Member

    Worked BEAUTIFULLY! Thanks so much for your help on that! It was becoming a pain! Very easy to follow instructions!
    black hawk likes this.
  3. Brogan

    Brogan XenForo Moderator Staff Member

    Don't forget that you will need to edit the file again after every upgrade as it will be overwritten.
  4. ragtek

    ragtek Guest

    Better way would be to create a add-on, which overwrites getExistingSearch to return always false ;)
    black hawk, borbole and Eliteoomph like this.
  5. Eliteoomph

    Eliteoomph Member

    ok thanks I am going to suggest this
    unless you want to attack it ragtek? ;)
    black hawk likes this.
  6. borbole

    borbole Well-Known Member

    Indeed. Why not mod this up Jake?
    black hawk likes this.
  7. ragtek

    ragtek Guest

  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I don't like maintaining addons for people unless I use them myself. :p

    And I like the kind of instruction that allows people to experience and learn the code. I try to be a teacher as much as possible.

    You are right though... it is easy to make this an addon. Thanks ragtek.
    gordy, Fuhrmann, black hawk and 2 others like this.

Share This Page