Changeset 2148:621d4c6f4e8c for inc/core
- Timestamp:
- 09/29/13 01:16:03 (12 years ago)
- Branch:
- dcRepo
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.repository.php
r2147 r2148 63 63 } 64 64 65 public function search($ search)65 public function search($pattern) 66 66 { 67 67 $result = array(); 68 68 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; 76 83 } 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); 77 97 } 78 98 return $result; … … 104 124 } 105 125 126 public static function sanitize(&$str, $_) 127 { 128 $str = strtolower(preg_replace('/[^A-Za-z0-9]/', '', $str)); 129 } 130 106 131 private static function compare($v1,$v2,$op) 107 132 {
Note: See TracChangeset
for help on using the changeset viewer.