Skip to content

Commit 7b0242f

Browse files
authored
Merge pull request 4x99#33 from 4x99/feature/修复GitHub高级搜索语法排序错乱
修复:GitHub 高级搜索语法排序错乱
2 parents 6934d10 + 1370bfe commit 7b0242f

File tree

2 files changed

+17
-59
lines changed

2 files changed

+17
-59
lines changed

app/Console/Commands/JobRunCommand.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,26 @@ public function handle()
7272
$this->log = Log::channel($this->signature);
7373
$this->log->info('Start job');
7474

75-
while ($job = $this->takeJob()) {
76-
if (!$this->service) {
77-
$this->createGitHubService();
78-
$this->whitelist = ConfigWhitelist::all()->keyBy('value');
79-
}
75+
if (!QueueJob::count()) {
76+
$this->log->info('The queue is empty');
77+
exit;
78+
}
8079

80+
$this->createGitHubService();
81+
$this->whitelist = ConfigWhitelist::all()->keyBy('value');
82+
83+
while ($job = $this->takeJob()) {
8184
$page = 1;
8285
$keyword = $job->keyword;
8386
$configJob = ConfigJob::where('keyword', $keyword)->first();
8487
$configJob->last_scan_at = date('Y-m-d H:i:s');
8588
do {
8689
$client = $this->service->getClient();
87-
$data = $this->searchCode($client, $keyword, $nextPage ?? null);
90+
$data = $this->searchCode($client, $keyword, $page);
8891
$count = $this->store($data, $configJob);
8992
$this->log->info('Stored', ['keyword' => $keyword, 'page' => $page, 'count' => $count]);
9093
$lastResponse = ResponseMediator::getPagination($client->getLastResponse());
91-
$nextPage = $lastResponse['next'] ?? false;
92-
} while ($nextPage && (++$page <= $configJob->scan_page));
94+
} while ($lastResponse['next'] && (++$page <= $configJob->scan_page));
9395
$configJob->save();
9496
}
9597

@@ -117,7 +119,6 @@ private function createGitHubService()
117119
private function takeJob()
118120
{
119121
if (!$job = QueueJob::orderBy('created_at')->first()) {
120-
$this->log->info('The queue is empty');
121122
return false;
122123
}
123124
$job->delete();
@@ -129,16 +130,14 @@ private function takeJob()
129130
*
130131
* @param $client
131132
* @param $keyword
132-
* @param null $url
133+
* @param int $page
133134
* @return array|bool|string
134135
*/
135-
private function searchCode($client, $keyword, $url = null)
136+
private function searchCode($client, $keyword, $page = 1)
136137
{
137138
try {
138-
if ($url) { // 非首页
139-
return ResponseMediator::getContent($client->getHttpClient()->get($url));
140-
}
141-
return $client->api('search')->code($keyword, 'indexed'); // 首页
139+
$keyword = sprintf('"%s"', $keyword); // 精确匹配
140+
return $client->api('search')->setPage($page)->code($keyword, 'indexed');
142141
} catch (Exception $e) {
143142
$this->log->warning($e->getMessage());
144143
return false;

resources/views/configJob/index.blade.php

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
tbar: {
3030
margin: '5 12 15 18',
3131
items: [
32-
{
33-
text: '帮助信息',
34-
iconCls: 'icon-page-star',
35-
handler: winHelp,
36-
},
3732
'->',
3833
{
3934
text: '新增任务',
@@ -156,7 +151,7 @@
156151
function winForm(data) {
157152
var win = Ext.create('Ext.window.Window', {
158153
title: '任务信息',
159-
width: 500,
154+
width: 600,
160155
iconCls: 'icon-page-wrench',
161156
layout: 'fit',
162157
items: [
@@ -174,27 +169,13 @@ function winForm(data) {
174169
name: 'keyword',
175170
fieldLabel: '扫描关键字',
176171
value: data.keyword,
177-
triggers: {
178-
search: {
179-
cls: 'icon-zoom',
180-
tooltip: '查看关键字搜索结果',
181-
handler: function () {
182-
var keyword = this.up('form').getValues().keyword;
183-
if (!keyword) {
184-
tool.toast('还未设置关键字!');
185-
return;
186-
}
187-
tool.winOpen(GitHub + 'search?o=desc&q=' + keyword + '&s=indexed&type=Code')
188-
}
189-
}
190-
}
191172
},
192173
{
193174
xtype: 'numberfield',
194175
name: 'scan_page',
195-
fieldLabel: '扫描页数',
176+
fieldLabel: '扫描页数(每页 30 条)',
196177
minValue: 1,
197-
value: data.scan_page ? data.scan_page : 5,
178+
value: data.scan_page ? data.scan_page : 3,
198179
},
199180
{
200181
xtype: 'numberfield',
@@ -258,28 +239,6 @@ function winForm(data) {
258239
}).show();
259240
}
260241
261-
function winHelp() {
262-
var content = '<div class="help">';
263-
content += '<p>1. 精确匹配:<span>keyword</span></p>';
264-
content += '<p>2. 关键字有空格或其他符号(引号):<span>"smtp.qq.com"</span></p>';
265-
content += '<p>3. 匹配多个关键字(AND):<span>mysql AND password</span>(同时匹配 mysql 和 password)</p>';
266-
content += '<p>4. 排除特定关键字(NOT):<span>mysql NOT localhost</span>(匹配 mysql 但不含 localhost)</p>';
267-
content += '<p>5. 扫描时 GitHub 会忽略以下符号:<span>@ . , : ; / \\ ` \' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ]</span></pre>';
268-
content += '<p><br/>更多关键字高级语法请浏览 ';
269-
content += '<a href="https://help.github.com/cn/github/searching-for-information-on-github/understanding-the-search-syntax" target="_blank">了解搜索语法</a> ';
270-
content += '或使用 <a href="https://github.com/search/advanced" target="_blank">高级搜索</a> 工具</p>';
271-
content += '</div>';
272-
273-
Ext.Msg.show({
274-
title: '关键字设置说明',
275-
maxWidth: 800,
276-
maxHeight: 600,
277-
modal: false,
278-
iconCls: 'icon-page-star',
279-
message: content,
280-
}).removeCls('x-unselectable');
281-
}
282-
283242
Ext.create('Ext.container.Container', {
284243
renderTo: Ext.getBody(),
285244
height: '100%',

0 commit comments

Comments
 (0)