Dotclear

Changeset 2148:621d4c6f4e8c


Ignore:
Timestamp:
09/29/13 01:16:03 (11 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
dcRepo
Message:

Better repository search engine (and other stuff)

Location:
inc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/lib.moduleslist.php

    r2147 r2148  
    115115     public function displayNavMenu() 
    116116     { 
    117           if (empty($this->modules)) { 
     117          if (empty($this->modules) || $this->getSearchQuery() !== null) { 
    118118               return $this; 
    119119          } 
     
    222222     } 
    223223 
     224     public static function isDistributedModule($module) 
     225     { 
     226          return in_array($module, array( 
     227               'aboutConfig', 
     228               'akismet', 
     229               'antispam', 
     230               'attachments', 
     231               'blogroll', 
     232               'blowupConfig', 
     233               'daInstaller', 
     234               'fairTrackbacks', 
     235               'importExport', 
     236               'maintenance', 
     237               'pages', 
     238               'pings', 
     239               'simpleMenu', 
     240               'tags', 
     241               'themeEditor', 
     242               'userPref', 
     243               'widgets' 
     244          )); 
     245     } 
     246 
    224247     public static function sortModules($modules, $field, $asc=true) 
    225248     { 
     
    270293 
    271294          # Sort modules by id 
    272           $modules = self::sortModules($this->modules, $sort_field, $this->sort_asc); 
     295          $modules = $this->getSearchQuery() === null ? 
     296               self::sortModules($this->modules, $sort_field, $this->sort_asc) : 
     297               $this->modules; 
    273298 
    274299          $count = 0; 
     
    303328               } 
    304329 
    305                if (in_array('old_version', $cols)) { 
     330               if (in_array('current_version', $cols)) { 
    306331                    echo  
    307                     '<td class="nowrap count">'.html::escapeHTML($module['old_version']).'</td>'; 
     332                    '<td class="nowrap count">'.html::escapeHTML($module['current_version']).'</td>'; 
    308333               } 
    309334 
  • inc/core/class.dc.repository.php

    r2147 r2148  
    6363     } 
    6464 
    65      public function search($search) 
     65     public function search($pattern) 
    6666     { 
    6767          $result = array(); 
    6868 
    69           foreach ($this->data['new'] as $module) 
    70           { 
    71                if ( preg_match('/'.$search.'/i',$module['id']) || 
    72                     preg_match('/'.$search.'/i',$module['name']) || 
    73                     preg_match('/'.$search.'/i',$module['desc'])) 
    74                { 
    75                     $result[] = $module; 
     69          # Split query into small clean words 
     70          $patterns = explode(' ', $pattern); 
     71          array_walk($patterns, array('dcRepository','sanitize')); 
     72 
     73          # For each modules 
     74          foreach ($this->data['new'] as $id => $module) { 
     75 
     76               # Split modules infos into small clean word 
     77               $subjects = explode(' ', $id.' '.$module['name'].' '.$module['desc']); 
     78               array_walk($subjects, array('dcRepository','sanitize')); 
     79 
     80               # Check contents 
     81               if (!($nb = preg_match_all('/('.implode('|', $patterns).')/', implode(' ', $subjects)))) { 
     82                    continue; 
    7683               } 
     84 
     85               # Add module to result 
     86               if (!isset($sorter[$id])) { 
     87                    $sorter[$id] = 0; 
     88                    $result[$id] = $module; 
     89               } 
     90 
     91               # Increment matches count 
     92               $sorter[$id] += $nb; 
     93          } 
     94          # Sort response by matches count 
     95          if (!empty($result)) { 
     96               array_multisort($sorter, SORT_DESC, $result); 
    7797          } 
    7898          return $result; 
     
    104124     } 
    105125 
     126     public static function sanitize(&$str, $_) 
     127     { 
     128          $str = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $str)); 
     129     } 
     130 
    106131     private static function compare($v1,$v2,$op) 
    107132     { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map