Initial commit

This commit is contained in:
ZLI263
2025-11-23 11:20:51 +08:00
commit 355e056ae7
1025 changed files with 123077 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
'use strict';
exports.main = async (event, context) => {
/**
* 根据搜索记录,设定时间间隔来归纳出热搜数据并存储在热搜表中
*/
const SEARCHHOT = 'opendb-search-hot'; // 热搜数据库名称
const SEARCHLOG = 'opendb-search-log'; // 搜索记录数据库名称
const SEARCHLOG_timeZone = 604800000; // 归纳搜索记录时间间隔毫秒数默认为最近7天
const SEARCHHOT_size = 10; // 热搜条数
const DB = uniCloud.database();
const DBCmd = DB.command;
const $ = DB.command.aggregate;
const SEARCHHOT_db = DB.collection(SEARCHHOT);
const SEARCHLOG_db = DB.collection(SEARCHLOG);
const timeEnd = Date.now() - SEARCHLOG_timeZone;
let {
data: searchHotData
} = await SEARCHLOG_db
.aggregate()
.match({
create_date: DBCmd.gt(timeEnd)
})
.group({
_id: {
'content': '$content',
},
count: $.sum(1)
})
.replaceRoot({
newRoot: $.mergeObjects(['$_id', '$$ROOT'])
})
.project({
_id: false
})
.sort({
count: -1
})
.end();
let now = Date.now();
searchHotData.map(item => {
item.create_date = now;
return item;
}).slice(0, SEARCHHOT_size);
// searchHotData = searchHotData.sort((a, b) => b.count - a.count).slice(0, SEARCHHOT_size);
return searchHotData.length ? await SEARCHHOT_db.add(searchHotData) : ''
};

View File

@@ -0,0 +1,20 @@
{
"name": "uni-analyse-searchhot",
"version": "1.0.0",
"description": "定时归纳热搜",
"main": "index.js",
"dependencies": {},
"cloudfunction-config": {
"triggers": [
{
"name": "analyse-searchHot",
"type": "timer",
"config": "0 0 *\/2 * * * *"
}
]
},
"origin-plugin-dev-name": "uni-starter",
"origin-plugin-version": "2.2.8",
"plugin-dev-name": "uni-starter",
"plugin-version": "2.2.8"
}