Skip to content

Commit c75836c

Browse files
committed
Improvements for rebuild and clear commands, removed unused functional (destroy connection, helpers), fix some tests.
1 parent ae80da1 commit c75836c

File tree

11 files changed

+15
-121
lines changed

11 files changed

+15
-121
lines changed

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
"orchestra/testbench": "3.1.*"
2222
},
2323
"autoload": {
24-
"files": [
25-
"src/Nqxcode/LuceneSearch/Support/helpers.php"
26-
],
2724
"psr-4": {
2825
"Nqxcode\\LuceneSearch\\": "src/Nqxcode/LuceneSearch",
2926
"tests\\": "tests/"

src/Nqxcode/LuceneSearch/Console/ClearCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php namespace Nqxcode\LuceneSearch\Console;
1+
<?php namespace Nqxcode\LuceneSearch\Console;
22

33
use Illuminate\Console\Command;
44
use Config;
@@ -15,7 +15,8 @@ public function fire()
1515
$this->output = new NullOutput;
1616
}
1717

18-
if ($result = rmdir_recursive(Config::get('laravel-lucene-search.index.path'))) {
18+
if (\File::isDirectory($indexPath = Config::get('laravel-lucene-search.index.path'))) {
19+
\File::deleteDirectory($indexPath);
1920
$this->info('Search index is cleared.');
2021
} else {
2122
$this->comment('There is nothing to clear..');

src/Nqxcode/LuceneSearch/Console/RebuildCommand.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ public function fire()
1919
$this->output = new NullOutput;
2020
}
2121

22-
if (is_dir(Config::get('laravel-lucene-search.index.path'))) {
23-
$this->call('search:clear');
24-
}
22+
$this->call('search:clear');
2523

2624
/** @var Search $search */
2725
$search = App::make('search');
@@ -36,17 +34,17 @@ public function fire()
3634

3735
if ($count === 0) {
3836
$this->comment(' No available models found. ');
39-
continue;
37+
return;
4038
}
4139

4240
$progress = new ProgressBar($this->getOutput(), $count);
41+
$progress->start();
4342

44-
$modelRepository->chunk(1000, function ($rows) use ($progress, $search) {
45-
foreach ($rows as $model) {
43+
$modelRepository->chunk(1000, function ($chunk) use ($progress, $search) {
44+
foreach ($chunk as $model) {
4645
$search->update($model);
4746
$progress->advance();
4847
}
49-
5048
});
5149

5250
$progress->finish();

src/Nqxcode/LuceneSearch/Index/Connection.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,4 @@ public function __construct($path, AnalyzerConfig $config)
5858
throw $e;
5959
}
6060
}
61-
62-
/**
63-
* Destroy the entire index.
64-
*/
65-
public function destroy()
66-
{
67-
$this->index = null;
68-
69-
if (is_dir($this->indexPath)) {
70-
rmdir_recursive($this->indexPath);
71-
}
72-
}
7361
}

src/Nqxcode/LuceneSearch/Model/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private function groupedSearchableIdsAsKeys(array $hits)
175175
/**
176176
* Get full list of models instances.
177177
*
178-
* @return Model[]
178+
* @return Model[]|Builder[]
179179
*/
180180
public function repositories()
181181
{

src/Nqxcode/LuceneSearch/Search.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ public function __construct(Connection $connection, Config $config)
6060
$this->config = $config;
6161
}
6262

63-
/**
64-
* Destroy the entire index.
65-
*
66-
* @return bool
67-
*/
68-
public function destroy()
69-
{
70-
$this->connection->destroy();
71-
}
72-
7363
/**
7464
* Find query hits for model in index.
7565
*

src/Nqxcode/LuceneSearch/Support/helpers.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/functional/FiltersTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ public function testMorphologySearch()
2626
$query = Search::query('clocks', '*');
2727
$this->assertEquals(3, $query->count());
2828

29-
$query = Search::query('bigger', '*');
30-
$this->assertEquals(2, $query->count());
31-
32-
$query = Search::query('smaller', '*');
33-
$this->assertEquals(3, $query->count());
29+
$query = Search::query('clocking', '*');
3430

3531
$query = Search::query('поиск тестового товара', '*', ['phrase' => false]);
3632
$this->assertEquals(1, $query->count());

tests/functional/HelpersTest.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/unit/Index/ConnectionTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public function tearDown()
2222
{
2323
parent::tearDown();
2424

25-
if (is_dir($this->indexPath)) {
26-
rmdir_recursive($this->indexPath);
27-
}
25+
\File::deleteDirectory($this->indexPath);
2826
}
2927

3028
public function testCreateIndex()
@@ -34,15 +32,6 @@ public function testCreateIndex()
3432
$this->assertEquals($this->indexPath, $index->getIndexPath());
3533
}
3634

37-
public function testDestroyIndex()
38-
{
39-
$index = $this->createConnection();
40-
$this->assertNotEmpty($index->getIndex());
41-
$index->destroy();
42-
$this->assertEmpty($index->getIndex());
43-
$this->assertFalse(is_dir($this->indexPath));
44-
}
45-
4635
private function createConnection()
4736
{
4837
return new Connection($this->indexPath, $this->analyzerConfig);

0 commit comments

Comments
 (0)