I added a function to qsfreq.xml to allow re-enabling of individual searches. It is called via the '/add' switch. If a search is disabled, you simply re-enable it with 'qsfreq /add <searchname>' Multiple searches can be specified at a time. 'qsfreq /add <searchname> <searchname> <searchname>'...

I checked the search in to CVS..

Usage:

qsfreq

[no switches] - Display the search frequency data. /clear - Clear the search frequency log. /disable_unused - Disable all searches not recorded in the frequency log. /enable_all - Re-enable all previously disabled searches. /add - Re-enable specific searches.

Examples: qsfreq /clear
qsfreq /disable_unused
qsfreq /enable_all
qsfreq qsfreq /add note alarm racetv comx imdb


Monty

<search function="qsfreq">
  <name>Quick Search Frequency Tool</name>
  <description>
    Display and manage search frequency log
    <div class="helpboxDescLabels">Switches:</div>
    <table class="helpboxDescTable">
      <tr><td>[no switches]</td><td> - </td><td>Display the search frequency data.</td></tr>
      <tr><td>/clear</td><td> - </td><td>Clear the search frequency log.</td></tr>
      <tr><td>/disable_unused</td><td> - </td><td>Disable all searches not recorded in the frequency log.</td></tr>
      <tr><td>/enable_all</td><td> - </td><td>Re-enable all previously disabled searches.</td></tr>
      <tr><td>/add</td><td> - </td><td>Re-enable specific searches.</td></tr>
    </table>
    <div class="helpboxDescLabels">Example:</div>
    <table class="helpboxDescTable">
      <tr><td>qsfreq</td></tr>
      <tr><td>qsfreq /clear</td></tr>
      <tr><td>qsfreq /add note alarm racetv comx imdb</td></tr>
    </table>
  </description>
  <category>Functions</category>
  <contributor>Glenn Carr</contributor>
  
  <script><![CDATA[
    function qsfreq( q )
    {
      if ( q == "?" )
      {
        nullArgs("qsfreq", q);
        return;
      }

      var args = parseArgs( q, "clear,disable_unused,add,enable_all" );
      if ( args.switches.length == 0 )
        return qsfreqDisplayFrequency();
        
      for (var i = 0; i < args.switches.length; i++)
      {
        sw = args.switches[i];
        switch ( sw.name )
        {
          case "clear":
            qsfreqClearFrequencyLog();
            return;
          case "disable_unused":
            qsfreqDisableUnusedSearches();
            return;
          case "enable_all":
            qsfreqEnableAllSearches();
            return;
          case "add":
            qsfreqEnableSingleSearches(args.q);
            return;
        }
      }
    }
    
    function qsfreqClearFrequencyLog()
    {
      if ( !confirm( "Are you sure you want to clear the search frequency log?" ) )
        return;
      
      try
      {
        writeFile( FREQUENCY_LOG, '' );
      }
      catch(e) { }
    }
    

    function qsfreqDisableUnusedSearches()
    {
      var frequencyLogContent = readFile( FREQUENCY_LOG );
      if ( frequencyLogContent == null )
      {
        alert( "Unable to find any frequency log data" );
        return;
      }
      
      var recentSearches = frequencyLogContent.replace(/\r\n/g, '\n').split('\n');
      var recentSearchHash = new Object();
      for (var i = 0; i < recentSearches.length; i++)
      {
        var searchFields = recentSearches[i].split( FREQ_LOG_DELIM );
        recentSearchHash[ searchFields[ 0 ] ] = true;
      }
      // Some searches we simply don't want to ever disable
      recentSearchHash[ 'gg' ] = true;
      recentSearchHash[ 'qsfind' ] = true;
      recentSearchHash[ 'qsfreq' ] = true;
      recentSearchHash[ 'configure' ] = true;
      
      var toDisable = new Array();
      var toEnable = new Array();
      var enabledSearches = getFiles( "searches\\*.xml" ).replace( /\.xml/gi, '' ).split('\n');
      var renames = new Array();
      for (var i = 0; i < enabledSearches.length; i++)
      {
        var search = enabledSearches[ i ];
        if ( !recentSearchHash.hasOwnProperty( search ) )
        {
          renames.push( { search:search, from:"searches\\" + search + ".xml", to:"searches\\" + search + ".disabled" } );
          toDisable.push( search );
        }
        else
        {
          toEnable.push( search );
        }
      }
      if ( renames.length == 0 )
      {
        alert( "Unused searches have already been disabled." );
        return;
      }
      if ( !confirm( "Are you sure you want to disable the following unused searches?\r\n\r\n" + toDisable.join( ', ' ) + "\r\n\r\nThese searches will remain enabled:\r\n\r\n" + toEnable.join( ', ' ) ) )
        return;
        
      var errors = new Array();
      var renamed = new Array();
      for ( var i = 0; i < renames.length; i++ )
      {
        if ( renameFile( renames[ i ].from, renames[ i ].to ) || 
             ( renameFile( renames[ i ].to, renames[ i ].to + "_" + (new Date()).getTime() ) && renameFile( renames[ i ].from, renames[ i ].to ) ) )
        {
          renamed.push( renames[ i ].search ); 
        }
        else
        {
          errors.push( renames[ i ].search );
        }
      }
      alert( ( ( renamed.length > 0 ) ? ( 'The following searches have been disabled:\r\n\r\n' + toDisable.join( ', ' ) ) : '' ) +
             ( ( errors.length > 0 ) ? ( '\r\n\r\nThere were problems disabling the following searches:\r\n\r\n' + errors.join( ', ' ) ) : '' ) +
             ( ( toEnable.length > 0 ) ? ( '\r\n\r\nThe following searches are still enabled:\r\n\r\n' + toEnable.join( ', ' ) ) : '' ) +
             ( ( renamed.length > 0 ) ? '\r\n\r\nClick OK to reload the search bar.' : '' ) );
      if ( renamed.length > 0 )
        reload();
    }


    function qsfreqEnableAllSearches()
    {
      var disabledSearches = getFiles( "searches\\*.disabled" ).replace( /\.disabled/gi, '' ).split( /\n+/ );
      var renamed = new Array();
      var errors = new Array();
      for (var i = 0; i < disabledSearches.length; i++)
      {
        var search = disabledSearches[ i ];
        if ( search == "" )
          continue;
        var from = "searches\\" + search + ".disabled";
        var to = "searches\\" + search + ".xml";
        if ( renameFile( from, to ) )
        {
          renamed.push( search );
        }
        else
        {
          renameFile( from, from + "_" + (new Date()).getTime() );
          errors.push( search );
        }
      }      
      if ( disabledSearches.length == 0 )
      {
        alert( "There are no disabled searches." );
        return;
      }
      alert( ( ( renamed.length > 0 ) ? ( 'The following searches have been enabled:\r\n\r\n' + renamed.join( ', ' ) + '' ) : 'There were no disabled searches.' ) +
             ( ( errors.length > 0 ) ? ( '\r\n\r\nThere were problems enabling the following searches:\r\n\r\n' + errors.join( ', ' ) ) : '' ) +
             ( ( renamed.length > 0 ) ? '\r\n\r\nClick OK to reload the search bar.' : '' ) );
      if ( renamed.length > 0 )
        reload();
    }

    function qsfreqEnableSingleSearches(searchlist)
    {
      parsedsearches = searchlist.split(" ");
      for (var i = 0; i < parsedsearches.length; i++)
      {
        var search = parsedsearches[i];
        var from = "searches\\" + search + ".disabled";
        var to = "searches\\" + search + ".xml";       
        //alert('rename ('+from+') to ('+to+')');
        renameFile( from, to );
        //renameFile( from, to + "_" + (new Date()).getTime() );
      }
      reload();
    }


    function qsfreqDisplayFrequency()
    {
      try
      {
        var frequencyLogContent = readFile( FREQUENCY_LOG );
      }
      catch(e) { }

      var html = new Array();
      html.push( '<table style="font-size: 11px; text-align: center; border-collapse: collapse" border="1" align="center" width="100%">' );

      if ( typeof qsfreqLogSearchFrequency == 'undefined' || qsfreqLogSearchFrequency == 0 )
        html.push( '<tr><td colspan="3"><b style="color: red">Search frequency logging is not enabled.</b>&nbsp;&nbsp;<br/><b>qsfreqLogSearchFrequency</b> should be set to 1 in your localprefs.js.</td></tr>' );

      html.push( '<tr><th>Search</th><th>Occurrences</th><th>Last Used</th></tr>' );
      var startLogDate = null;
      if (frequencyLogContent)
      {
        var recentSearches = frequencyLogContent.replace(/\r\n/g, '\n').split('\n');
        var lastDate = new Date();

        for (var i = 0; i < recentSearches.length; i++)
        {
          var searchFields = recentSearches[i].split( FREQ_LOG_DELIM );
          if ( searchFields[ 0 ] == '[file_created]' )
          {
            startLogDate = new Date();
            startLogDate.setTime( searchFields[ 2 ] );
            continue;
          }
          
          html.push( '<tr><td>' );
          html.push( searchFields[ 0 ] ); // search
          html.push( '</td><td>' );
          html.push( searchFields[ 1 ] ); // occurrences
          html.push( '</td><td><nobr>' );
          var dt = new Date();
          dt.setTime( searchFields[ 2 ] );
          html.push( dt.toString() ); // last occurrence
          html.push( '</nobr></td></tr>' );

          lastDate = dt;
        }
        html.push( '<tr><td colspan="3">(' );
        html.push( recentSearches.length );
        html.push( ' of ' );

        var installedSearchCount = 0;
        try
        {
          installedSearchCount += getFiles( "searches\\*.xml" ).split('\n').length;
          // Probably not a great idea to mess with local searches
          // installedSearchCount += getFiles( "localsearches\\*.xml" ).split('\n').length;
        } catch ( e ) { }

        html.push( installedSearchCount );
        html.push( ' installed searches' );
        if ( startLogDate != null )
        {
          html.push( ' have been used since ' );
          html.push( startLogDate.toString() );
        }
        html.push( '.)</td></tr>' );
      }
      else
      {
        html.push( '<tr><td colspan="3">No searches recorded. Make sure that <b>qsfreqLogSearchFrequency</b> has been set in your localprefs.js.</td></tr>' );
      }
      html.push( '</table>' );
      html = html.join( '' );

      if ( typeof freqLogPopup == 'undefined' )
        freqLogPopup = window.createPopup();
      var dictPopupBody = freqLogPopup.document.body;

      dictPopupBody.innerHTML = '<table id=defTable style="font-size: 70%; border: inset 2px" height="100%" width="100%"><tr><td style="padding: 5px 5px">' + html + "</td></tr></table>";

      freqLogPopup.document.body.style.border="outset 2px";
      freqLogPopup.document.body.style.padding="1px 1px; background: navy";
      freqLogPopup.document.body.style.background='menu';
      freqLogPopup.document.body.style.overflowY='auto';
      freqLogPopup.document.body.style.fontFamily='Verdana';

      // Temporarily show the popup to determine the proper final height for the popup.
      var windowW = 400;
      freqLogPopup.show(0, 0, windowW, 0);
      var windowH = dictPopupBody.scrollHeight + 6;
      freqLogPopup.hide();
      freqLogPopup.document.all.defTable.style.width = windowW - 5;
      windowH = windowH > window.screen.height/2 ? window.screen.height/2 : windowH;
      freqLogPopup.show((buttonalign == "left" ? 0 : document.body.clientWidth - windowW), -windowH, windowW, windowH, document.body);

      return '';
    }
  ]]></script>

  <copyright>
  Copyright (c) 2002-2006 David Bau, Glenn Carr
  Distributed under the terms of the
  GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
  </copyright>
</search>
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
To unsubscribe visit:
https://lists.sourceforge.net/lists/listinfo/dqsd-users
DQSD-Users@lists.sourceforge.net
http://sourceforge.net/mailarchive/forum.php?forum_id=8601

Reply via email to