|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Nip Framework |
|
5
|
|
|
* |
|
6
|
|
|
* @category Nip |
|
7
|
|
|
* @copyright 2009 Nip Framework |
|
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License |
|
9
|
|
|
* @version SVN: $Id: Fulltext.php 14 2009-04-13 11:24:22Z victor.stanciu $ |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
class Nip_Helper_Fulltext extends Nip\Helpers\AbstractHelper { |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
public function buildString($keywords, $mode = 'any') { |
|
15
|
|
|
$return = ""; |
|
16
|
|
|
|
|
17
|
|
|
$keywords = explode(" ", $keywords); |
|
18
|
|
|
|
|
19
|
|
|
switch ($mode) { |
|
20
|
|
|
case "any": |
|
21
|
|
|
foreach ($keywords as $item) { |
|
22
|
|
|
$return .= $this->matchNumbers($item).'* '; |
|
23
|
|
|
} |
|
24
|
|
|
break; |
|
25
|
|
|
|
|
26
|
|
|
case "all": |
|
27
|
|
|
if (count($keywords) == 1) { |
|
28
|
|
|
$return .= $this->matchNumbers(reset($keywords)).'* '; |
|
29
|
|
|
} else { |
|
30
|
|
|
foreach ($keywords as $item) { |
|
31
|
|
|
$return .= '+'. $this->matchNumbers($item).'* '; |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
break; |
|
36
|
|
|
case "exact": |
|
37
|
|
|
foreach ($keywords as $item) { |
|
38
|
|
|
$return .= $this->matchNumbers($item).' '; |
|
39
|
|
|
} |
|
40
|
|
|
$return = '+"'.$return.'"'; |
|
41
|
|
|
break; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$return = strtolower(trim($return)); |
|
45
|
|
|
|
|
46
|
|
|
return $return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
private function matchNumbers($input) { |
|
51
|
|
|
$stripped = array("%", ",", "."); |
|
52
|
|
|
$replaced = array("__", "_", "_"); |
|
53
|
|
|
|
|
54
|
|
|
if (is_numeric(str_replace($stripped, "", $input))) { |
|
55
|
|
|
return str_replace($stripped, $replaced, $input); |
|
56
|
|
|
} else { |
|
57
|
|
|
return $input; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns singleton instance |
|
64
|
|
|
* |
|
65
|
|
|
* @return Nip_Helper_Fulltext |
|
66
|
|
|
*/ |
|
67
|
|
|
static public function instance() { |
|
|
|
|
|
|
68
|
|
|
static $instance; |
|
69
|
|
|
if (!($instance instanceof self)) { |
|
70
|
|
|
$instance = new self(); |
|
71
|
|
|
} |
|
72
|
|
|
return $instance; |
|
73
|
|
|
} |
|
74
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.