Dotclear

Changeset 2222:30fe556de226


Ignore:
Timestamp:
10/03/13 00:57:41 (12 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
dcRepo
Message:

Enhance repository search engine (and some fix)

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • admin/blog_theme.php

    r2220 r2222  
    137137               ->newList('theme-update') 
    138138               ->setModules($modules) 
    139                ->setPageTab('update') 
     139               ->setPageTab('themes') 
    140140               ->displayModulesList( 
    141141                    /*cols */      array('sshot', 'name', 'desc', 'author', 'version', 'current_version', 'parent'), 
    142                     /* actions */  array('update') 
     142                    /* actions */  array('update', 'delete') 
    143143               ); 
    144144 
     
    207207               ->displayNavMenu() 
    208208               ->displayModulesList( 
    209                     /* cols */          array('expander', 'sshot', 'name', 'config', 'desc', 'author', 'version', 'parent', 'details', 'support'), 
     209                    /* cols */          array('expander', 'sshot', 'name', 'score', 'config', 'desc', 'author', 'version', 'parent', 'details', 'support'), 
    210210                    /* actions */  array('install'), 
    211211                    /* nav limit */     true 
  • admin/js/_plugins.js

    r2171 r2222  
    7878                                var support = $(rsp).find('support').text(); 
    7979                                        var box = document.createElement('div'); 
    80                                 var dl = document.createElement('ul'); 
    81                                 dl.className = "mod-more"; 
     80                                var bloc = document.createElement('ul'); 
     81                                bloc.className = "mod-more"; 
    8282                                 
    8383                                if (author) { 
    84                                         $(dl).append($('<li class="module-author">'+dotclear.msg.module_author+' '+author+'</li>')); 
     84                                        $(bloc).append($('<li class="module-author">'+dotclear.msg.module_author+' '+author+'</li>')); 
    8585                                } 
    8686                                if (details) { 
     
    9191                                                dd += '<a class="module-support" href="'+support+'">'+dotclear.msg.module_support+'</a>'; 
    9292                                        } 
    93                                         $(dl).append($('<li>'+dotclear.msg.module_help+' '+dd+'</li>')); 
     93                                        $(bloc).append($('<li>'+dotclear.msg.module_help+' '+dd+'</li>')); 
    9494                                } 
    9595 
    96                                 $(td).append($(box).addClass('two-boxes').append(dl)); 
     96                                $(td).append($(box).addClass('two-boxes').append(bloc)); 
    9797                                 
    9898                                var section = $(rsp).find('section').text(); 
     
    100100                                 
    101101                                        var boxb = document.createElement('div'); 
    102                                 var dlb = document.createElement('ul'); 
    103                                 dlb.className = "mod-more"; 
     102                                var blocb = document.createElement('ul'); 
     103                                blocb.className = "mod-more"; 
    104104                                 
    105105                                if (section) { 
    106                                         $(dlb).append($('<li class="module-section">'+dotclear.msg.module_section+' '+section+'</li>')); 
     106                                        $(blocb).append($('<li class="module-section">'+dotclear.msg.module_section+' '+section+'</li>')); 
    107107                                } 
    108108                                if (tags) { 
    109                                         $(dlb).append($('<li class="module-tags">'+dotclear.msg.module_tags+' '+tags+'</li>')); 
     109                                        $(blocb).append($('<li class="module-tags">'+dotclear.msg.module_tags+' '+tags+'</li>')); 
    110110                                } 
    111                                 $(td).append($(boxb).addClass('two-boxes').append(dlb)); 
     111                                $(td).append($(boxb).addClass('two-boxes').append(blocb)); 
    112112                        } else { 
    113113                                alert($(rsp).find('message').text()); 
     
    151151$(function() { 
    152152        $('table.modules.expandable tr:not(.line)').each(function() { 
    153                 dotclear.modulesExpander(this,$('table.modules tr.line')); 
     153                dotclear.modulesExpander(this,$('table.modules.expandable tr.line')); 
    154154        }); 
    155155        $('table.modules.expandable tr.line').each(function() { 
  • admin/plugins.php

    r2219 r2222  
    229229               ->displayNavMenu() 
    230230               ->displayModulesList( 
    231                     /* cols */          array('expander', 'name', 'version', 'desc'), 
     231                    /* cols */          array('expander', 'name', 'score', 'version', 'desc'), 
    232232                    /* actions */  array('install'), 
    233233                    /* nav limit */     true 
  • inc/admin/lib.moduleslist.php

    r2221 r2222  
    269269                    'tags'                   => '', 
    270270                    'details'                => '', 
    271                     'sshot'             => '' 
     271                    'sshot'             => '', 
     272                    'score'                  => 0 
    272273               ), 
    273274               # Module's values 
     
    314315          } 
    315316 
     317          if (in_array('score', $cols) && $this->getSearchQuery() !== null && defined('DC_DEBUG') && DC_DEBUG) { 
     318               echo  
     319               '<th class="nowrap">'.__('Score').'</th>'; 
     320          } 
     321 
    316322          if (in_array('version', $cols)) { 
    317323               echo  
     
    381387                    html::escapeHTML($module['name']) 
    382388               ).'</td>'; 
     389 
     390               # Display score only for debug purpose 
     391               if (in_array('score', $cols) && $this->getSearchQuery() !== null && defined('DC_DEBUG') && DC_DEBUG) { 
     392                    echo  
     393                    '<td class="module-version nowrap count"><span class="debug">'.$module['score'].'</span></td>'; 
     394               } 
    383395 
    384396               if (in_array('version', $cols)) { 
     
    863875               } 
    864876 
     877               # Display score only for debug purpose 
     878               if (in_array('score', $cols) && $this->getSearchQuery() !== null && defined('DC_DEBUG') && DC_DEBUG) { 
     879                    $line .=  
     880                    '<p class="module-score debug">'.sprintf(__('Score: %s'), $module['score']).'</p>'; 
     881               } 
     882 
    865883               if (in_array('sshot', $cols)) { 
    866884                    # Screenshot from url 
     
    901919               } 
    902920 
     921               if (in_array('current_version', $cols)) { 
     922                    $line .=  
     923                    '<span class="module-current-version">'.sprintf(__('(current version %s)'),html::escapeHTML($module['current_version'])).'</span> '; 
     924               } 
     925 
    903926               if (in_array('parent', $cols) && $has_parent) { 
    904927                    if ($is_parent_present) { 
     
    910933                         '<span class="module-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($parent)).'</span> '; 
    911934                    } 
    912                } 
    913  
    914                if (in_array('version', $cols)) { 
    915                     $line .=  
    916                     '<span class="module-version">'.sprintf(__('version %s'),html::escapeHTML($module['version'])).'</span> '; 
    917935               } 
    918936 
  • inc/core/class.dc.store.parser.php

    r2216 r2222  
    1515@ingroup DC_CORE 
    1616@brief Repository modules XML feed parser 
     17@since 2.6 
    1718 
    1819Provides an object to parse XML feed of modules from a repository. 
  • inc/core/class.dc.store.php

    r2216 r2222  
    1515@ingroup DC_CORE 
    1616@brief Repository modules XML feed reader 
     17@since 2.6 
    1718 
    1819Provides an object to parse XML feed of modules from repository. 
     
    2425     /** @var  object    dcModules instance */ 
    2526     public $modules; 
     27 
     28     /** @var  array     Modules fields to search on and their weighting */ 
     29     public static $weighting = array('id' => 10, 'name' => 8, 'author' => 6, 'tags' => 4, 'desc' => 2); 
    2630 
    2731     /** @var  string    User agent used to query repository */ 
     
    126130 
    127131          # Split query into small clean words 
    128           $patterns = explode(' ', $pattern); 
    129           array_walk($patterns, array('dcStore','sanitize')); 
     132          if (!($patterns = self::patternize($pattern))) { 
     133               return $result; 
     134          } 
    130135 
    131136          # For each modules 
    132137          foreach ($this->data['new'] as $id => $module) { 
    133  
    134                # Split modules infos into small clean word 
    135                $subjects = explode(' ', $id.' '.$module['name'].' '.$module['desc']); 
    136                array_walk($subjects, array('dcStore','sanitize')); 
    137  
    138                # Check contents 
    139                if (!($nb = preg_match_all('/('.implode('|', $patterns).')/', implode(' ', $subjects), $_))) { 
    140                     continue; 
    141                } 
    142  
    143                # Add module to result 
    144                if (!isset($sorter[$id])) { 
    145                     $sorter[$id] = 0; 
    146                     $result[$id] = $module; 
    147                } 
    148  
    149                # Increment matches count 
    150                $sorter[$id] += $nb; 
    151                $result[$id]['accuracy'] = $sorter[$id]; 
     138               $module['id'] = $id; 
     139 
     140               # Loop through required module fields 
     141               foreach(self::$weighting as $field => $weight) { 
     142 
     143                    # Skip fields which not exsist on module 
     144                    if (empty($module[$field])) { 
     145                         continue; 
     146                    } 
     147 
     148                    # Split field value into small clean word 
     149                    if (!($subjects = self::patternize($module[$field]))) { 
     150                         continue; 
     151                    } 
     152 
     153                    # Check contents 
     154                    if (!($nb = preg_match_all('/('.implode('|', $patterns).')/', implode(' ', $subjects), $_))) { 
     155                         continue; 
     156                    } 
     157 
     158                    # Add module to result 
     159                    if (!isset($sorter[$id])) { 
     160                         $sorter[$id] = 0; 
     161                         $result[$id] = $module; 
     162                    } 
     163 
     164                    # Increment score by matches count * field weight 
     165                    $sorter[$id] += $nb * $weight; 
     166                    $result[$id]['score'] = $sorter[$id]; 
     167               } 
    152168          } 
    153169          # Sort response by matches count 
     
    217233 
    218234     /** 
    219       * Sanitize string. 
     235      * Split and clean pattern. 
    220236      * 
    221237      * @param string    $str      String to sanitize 
    222       * @param null $_        Unused    param 
    223       */ 
    224      public static function sanitize(&$str, $_) 
    225      { 
    226           $str = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $str)); 
     238      * @return     array     Array of cleaned pieces of string or false if none 
     239      */ 
     240     public static function patternize($str) 
     241     { 
     242          $arr = array(); 
     243 
     244          foreach(explode(' ', $str) as $_) { 
     245               $_ = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $_)); 
     246               if (strlen($_) > 2) { 
     247                    $arr[] = $_; 
     248               } 
     249          } 
     250 
     251          return empty($arr) ? false : $arr; 
    227252     } 
    228253 
  • inc/core/class.dc.store.reader.php

    r2216 r2222  
    1515@ingroup DC_CORE 
    1616@brief Repository modules XML feed reader 
     17@since 2.6 
    1718 
    1819Provides an object to parse XML feed of modules from repository. 
Note: See TracChangeset for help on using the changeset viewer.

Sites map