From cd0919cf690321f32b45330ec0ccf58981920052 Mon Sep 17 00:00:00 2001 From: bingshuo <565183519@qq.com> Date: Sun, 31 May 2026 13:38:47 +0800 Subject: [PATCH] =?UTF-8?q?D118=20step-5=20=C2=B7=20=E5=85=89=E6=B9=96?= =?UTF-8?q?=E5=8E=9F=E7=94=9F=E6=95=B0=E6=8D=AE=E5=BA=93=20=C2=B7=20ripgre?= =?UTF-8?q?p=E6=90=9C=E7=B4=A2=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- native-repo/modules/step-5-hldp-search.js | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 native-repo/modules/step-5-hldp-search.js diff --git a/native-repo/modules/step-5-hldp-search.js b/native-repo/modules/step-5-hldp-search.js new file mode 100644 index 0000000..6538238 --- /dev/null +++ b/native-repo/modules/step-5-hldp-search.js @@ -0,0 +1,43 @@ +/** + * HLDP-ZY://native-repo/module/step-5 + * 光湖原生数据库 · 第5步 · ripgrep搜索模块 + * + * @chain: D118 · 2026-05-31 + * @module: hldp-search + * @step: 第5步 / 共8步 + * @deploy: BS-SG-002 + * + * hldpSearch(query) → rg 执行 → HLDP格式返回 + * 输入: query 字符串 + * 输出: [{ file, line, content }] + */ + +const { execSync } = require('child_process'); +const { NATIVE_DIR } = require('./step-2-git-init'); + +function hldpSearch(query) { + try { + const result = execSync( + `rg -n --no-heading -M 200 "${query.replace(/[$"\\]/g, '\\$&')}" ${NATIVE_DIR} --glob '!.git' --glob '!node_modules' 2>/dev/null`, + { encoding: 'utf8', timeout: 10000, maxBuffer: 1024 * 1024 } + ); + + if (!result.trim()) return { ok: true, query, count: 0, results: [] }; + + const results = result.trim().split('\n').slice(0, 50).map(line => { + const [file, lnum, ...rest] = line.split(':'); + return { + file: file.replace(NATIVE_DIR + '/', ''), + line: parseInt(lnum), + content: rest.join(':').trim(), + }; + }); + + return { ok: true, query, count: results.length, results }; + } catch (e) { + if (e.status === 1) return { ok: true, query, count: 0, results: [] }; + return { ok: false, error: e.message }; + } +} + +module.exports = { hldpSearch };