Skip to content

Commit 2163e9b

Browse files
committed
added ability to merge old result with new ones
1 parent 085a18c commit 2163e9b

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

resources/config/restricted.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
<?php
2-
/**
3-
* Created by PhpStorm.
4-
* User: Emmy
5-
* Date: 11/30/2016
6-
* Time: 2:28 AM
7-
*/
8-
92
return [
103

4+
/*
5+
|--------------------------------------------------------------------------
6+
| File path
7+
|--------------------------------------------------------------------------
8+
|
9+
| File name and path to save the indexed words
10+
|
11+
|
12+
|
13+
*/
1114
'file_path' => public_path("restricted-usernames.txt"),
1215

16+
/*
17+
|--------------------------------------------------------------------------
18+
| Index level
19+
|--------------------------------------------------------------------------
20+
|
21+
| How deep do u want us to crawl your routes?
22+
| Ex www.mywebsite.com/segment1/segmen2/segment3
23+
| setting this value to '2', will allow indexing of segment1 and segment2
24+
| and exclude segment3
25+
|
26+
*/
1327
'index_level' => 2,
1428

29+
/*
30+
|--------------------------------------------------------------------------
31+
| Should merge
32+
|--------------------------------------------------------------------------
33+
|
34+
| Do you want to merge the new result with the old one?
35+
|
36+
|
37+
*/
38+
'merge' => true,
39+
1540
];

src/commands/CrawlRoutes.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,23 @@ public function crawl()
9595
}
9696
}
9797

98-
$data = collect($data)->unique()->sort();
98+
$data = collect($data)->unique();
9999
$this->store($data);
100100

101101
return $data->count();
102102
}
103103

104104
function store($routes){
105105
$fileName = $this->fileName;
106+
if(config('restricted.merge') && file_exists($fileName)){
107+
$old = collect(explode("\r\n", file_get_contents($fileName)))
108+
->map(function($value){
109+
return preg_replace("/\s/", '', $value);
110+
})->all();
111+
$routes->merge($old);
112+
}
106113

107-
$input = $routes->implode("\r\n");
114+
$input = $routes->unique()->sort()->implode("\r\n");
108115
$file = fopen($fileName, 'w+');
109116
fwrite($file, $input);
110117
fclose($file);

0 commit comments

Comments
 (0)