1 | <?php |
||
16 | class Index |
||
17 | { |
||
18 | /** |
||
19 | * @var LuceneIndex |
||
20 | */ |
||
21 | private $index; |
||
22 | |||
23 | /** |
||
24 | * @var string|boolean $path |
||
25 | */ |
||
26 | protected $path; |
||
27 | |||
28 | /** |
||
29 | * Open |
||
30 | * |
||
31 | * @param bool $path |
||
32 | * @param bool $forceCreate |
||
33 | * @return $this |
||
34 | * @throws ExceptionInterface |
||
35 | * @throws \Exception |
||
36 | */ |
||
37 | 9 | public function open($path = false, $forceCreate = true) |
|
45 | |||
46 | /** |
||
47 | * @param integer $limit |
||
48 | * @return $this |
||
49 | */ |
||
50 | 1 | public function limit($limit) |
|
55 | |||
56 | /** |
||
57 | * Create Index |
||
58 | * |
||
59 | * Extends the Lucene "open" method to create the index if it doesn't exist. |
||
60 | * |
||
61 | * @param string|boolean $path |
||
62 | * @param boolean $forceCreate |
||
63 | * @return SearchIndexInterface |
||
64 | * @throws \Exception |
||
65 | */ |
||
66 | 8 | private function createIndex($path, $forceCreate = true) |
|
67 | 1 | { |
|
68 | try { |
||
69 | 8 | $index = Lucene::open($path); |
|
70 | 8 | } catch (ExceptionInterface $error) { |
|
71 | 8 | if ($forceCreate) { |
|
72 | 7 | $index = Lucene::create($path); |
|
73 | 7 | } else { |
|
74 | 1 | throw $error; |
|
75 | } |
||
76 | } |
||
77 | |||
78 | 7 | return $index; |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param $path |
||
83 | */ |
||
84 | 20 | public function setPath($path) |
|
88 | |||
89 | /** |
||
90 | * @return string |
||
91 | * @throws \Exception |
||
92 | */ |
||
93 | 9 | protected function path() |
|
101 | |||
102 | /** |
||
103 | * @return LuceneIndex |
||
104 | */ |
||
105 | 5 | public function get() |
|
109 | } |
||
110 |