forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisaka-search.sh
More file actions
executable file
路65 lines (55 loc) 路 1.57 KB
/
Copy pathmisaka-search.sh
File metadata and controls
executable file
路65 lines (55 loc) 路 1.57 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
#!/usr/bin/env bash
# MisakaNet Search Plugin
# Usage: source scripts/misaka-search.sh
# misaka-search "your search query"
# mk "your search query"
#
# Docs: https://github.com/Ikalus1988/MisakaNet#search
set -euo pipefail
_misaka_search() {
if [ $# -eq 0 ]; then
echo "Usage: misaka-search <query>"
echo "Example: misaka-search 'database locked'"
return 1
fi
local query="$*"
if [ -z "${MISAKANET_DIR:-}" ]; then
echo "Error: MISAKANET_DIR environment variable is not set." >&2
return 1
fi
if [ ! -d "$MISAKANET_DIR" ]; then
echo "Error: MISAKANET_DIR='$MISAKANET_DIR' does not exist." >&2
return 1
fi
if [ ! -f "$MISAKANET_DIR/search_knowledge.py" ]; then
echo "Error: search_knowledge.py not found in MISAKANET_DIR." >&2
return 1
fi
cd "$MISAKANET_DIR" || return 1
python3 search_knowledge.py "$query" --top 5 --json 2>/dev/null | python3 -c "
import json, sys
try:
results = json.load(sys.stdin)
if not results:
print('No results found.')
sys.exit(0)
for i, r in enumerate(results[:5]):
title = r.get('title', 'Untitled')
domain = r.get('domain', 'unknown')
score = r.get('score', 0)
path = r.get('path', '?')
print(f'{i+1}. {title}')
print(f' Domain: {domain}')
print(f' Score: {score:.2f}')
print(f' Path: {path}')
print()
except Exception as e:
print(f'Search failed: {e}')
"
}
misaka-search() {
_misaka_search "$@"
}
mk() {
_misaka_search "$@"
}