Advertisement:

Author Topic: top / popular searches - how to?  (Read 349 times)

butterfly

  • Jr. Member
  • **
  • Posts: 80
top / popular searches - how to?
« on: November 14, 2018, 12:17:36 pm »
Hi

Is any way (function, plugin?) to keep searches in osclass and display it in case of category, e.g:

Category "Animals"
Popular searches -> cats, dog...

Category "Cars"
Popular searches -> ford focus, toyota corolla, peugot 206...

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1682
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: top / popular searches - how to?
« Reply #1 on: November 14, 2018, 05:56:44 pm »
You can enable saving the searches from admin area.

butterfly

  • Jr. Member
  • **
  • Posts: 80
Re: top / popular searches - how to?
« Reply #2 on: November 15, 2018, 12:42:03 am »
Hi Marius

Yes, I can, i did this, and I have a lot of data, but what now?
How to manage this data?
How to display them based on category?

Any idea?

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1682
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: top / popular searches - how to?
« Reply #3 on: November 15, 2018, 08:21:17 am »
oc-includes/osclass/helpers/hSearch.php

Code: [Select]
    /**********************
     ** LATEST SEARCHES **
     **********************/
    /**
     * Gets the latest searches done in the website
     *
     * @param int $limit
     * @return array
     */
    function osc_get_latest_searches($limit = 20) {
        if ( !View::newInstance()->_exists('latest_searches') ) {
            View::newInstance()->_exportVariableToView('latest_searches', LatestSearches::newInstance()->getSearches($limit) );
        }
        return View::newInstance()->_get('latest_searches');
    }

    /**
     * Gets the total number of latest searches done in the website
     *
     * @return int
     */
    function osc_count_latest_searches() {
        if ( !View::newInstance()->_exists('latest_searches') ) {
            View::newInstance()->_exportVariableToView('latest_searches', LatestSearches::newInstance()->getSearches() );
        }
        return View::newInstance()->_count('latest_searches');
    }

    /**
     * Gets the next latest search
     *
     * @return array
     */
    function osc_has_latest_searches() {
        if ( !View::newInstance()->_exists('latest_searches') ) {
            View::newInstance()->_exportVariableToView('latest_searches', LatestSearches::newInstance()->getSearches() );
        }
        return View::newInstance()->_next('latest_searches');
    }

    /**
     * Gets the current latest search
     *
     * @return array
     */
    function osc_latest_search() {
        if (View::newInstance()->_exists('latest_searches')) {
            return View::newInstance()->_current('latest_searches');
        }
        return null;
    }

    /**
     * Gets the current latest search pattern
     *
     * @return string
     */
    function osc_latest_search_text() {
        return osc_field(osc_latest_search(), 's_search', '');
    }

    /**
     * Gets the current latest search date
     *
     * @return string
     */
    function osc_latest_search_date() {
        return osc_field(osc_latest_search(), 'd_date', '');
    }

    /**
     * Gets the current latest search total
     *
     * @return string
     */
    function osc_latest_search_total() {
        return osc_field(osc_latest_search(), 'i_total', '');
    }

Search in the same file for other helper functions regarding category.
« Last Edit: November 15, 2018, 08:23:17 am by marius-ciclistu »

butterfly

  • Jr. Member
  • **
  • Posts: 80
Re: top / popular searches - how to?
« Reply #4 on: November 15, 2018, 02:08:03 pm »
Tkanks @marius

Your code display latest 20 searches in case of category, but how to display POPULAR searches?

MagicM

  • Newbie
  • *
  • Posts: 17
Re: top / popular searches - how to?
« Reply #5 on: May 16, 2019, 11:20:53 pm »
Tkanks @marius

Your code display latest 20 searches in case of category, but how to display POPULAR searches?

That would be nice too, any solution?