-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathBlogSuperSearchBiz.php
More file actions
102 lines (89 loc) · 2.89 KB
/
Copy pathBlogSuperSearchBiz.php
File metadata and controls
102 lines (89 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace Module\Blog\Core;
use ModStart\Core\Dao\ModelUtil;
use ModStart\Core\Util\HtmlUtil;
use ModStart\Core\Util\TagUtil;
use Module\Vendor\Provider\SuperSearch\AbstractSuperSearchBiz;
use Module\Vendor\Provider\SuperSearch\AbstractSuperSearchProvider;
use Module\Vendor\Provider\SuperSearch\FieldTypes;
use Module\Vendor\Provider\SuperSearch\SuperSearchProvider;
class BlogSuperSearchBiz extends AbstractSuperSearchBiz
{
const NAME = 'blog';
public function name()
{
return self::NAME;
}
public function title()
{
return '博客';
}
public function providerName()
{
return modstart_config('Blog_BlogSuperSearchProvider');
}
public function fields()
{
return [
'id' => ['type' => FieldTypes::F_LONG],
'isPublished' => ['type' => FieldTypes::F_LONG],
'isTop' => ['type' => FieldTypes::F_LONG],
'categoryId' => ['type' => FieldTypes::F_LONG],
'title' => ['type' => FieldTypes::F_TEXT],
'summary' => ['type' => FieldTypes::F_TEXT],
'content' => ['type' => FieldTypes::F_TEXT],
'tag' => ['type' => FieldTypes::F_KEYWORD],
];
}
public function syncBatch(AbstractSuperSearchProvider $provider, $nextId)
{
$ret = ModelUtil::batch('blog', $nextId, 1000);
BlogSuperSearchBiz::syncUpsert($ret['records'], false);
$data = [];
$data['count'] = count($ret['records']);
$data['nextId'] = $ret['nextId'];
return $data;
}
/**
* @return AbstractSuperSearchProvider
*/
public static function provider()
{
return SuperSearchProvider::get(modstart_config('Blog_BlogSuperSearchProvider'));
}
public static function syncUpsert($records, $checkExists = true)
{
$provider = self::provider();
if (empty($provider)) {
return;
}
if ($checkExists) {
$provider->ensureBucket('blog');
}
foreach ($records as $record) {
if (is_string($record['tag'])) {
$tags = TagUtil::string2Array($record['tag']);
} else {
$tags = $record['tag'];
}
$provider->upsert('blog', $record['id'], [
'id' => intval($record['id']),
'isPublished' => intval($record['isPublished']),
'isTop' => intval($record['isTop']),
'categoryId' => intval($record['categoryId']),
'title' => $record['title'],
'summary' => $record['summary'],
'content' => HtmlUtil::text($record['content']),
'tag' => $tags,
]);
}
}
public static function syncDelete($id)
{
$provider = self::provider();
if (empty($provider)) {
return;
}
$provider->delete('blog', $id);
}
}