MCPcopy
hub / github.com/UdaraJay/Pile / Search

Function Search

src/renderer/pages/Pile/Search/index.jsx:54–221  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52};
53
54export default function Search() {
55 const { currentTheme, setTheme } = usePilesContext();
56 const {
57 initVectorIndex,
58 rebuildVectorIndex,
59 query,
60 search,
61 searchOpen,
62 setSearchOpen,
63 vectorSearch,
64 } = useIndexContext();
65 const [container, setContainer] = useState(null);
66 const [ready, setReady] = useState(false);
67 const [text, setText] = useState('');
68 const [querying, setQuerying] = useState(false);
69 const [response, setResponse] = useState([]);
70 const [options, setOptions] = useState({
71 dateRange: '',
72 onlyHighlighted: false,
73 notReplies: false,
74 hasAttachments: false,
75 sortOrder: 'relevance',
76 semanticSearch: false,
77 });
78
79 const onChangeText = (e) => {
80 setText(e.target.value);
81 };
82
83 const onSubmit = useCallback(() => {
84 if (text === '') return;
85 setQuerying(true);
86
87 if (options.semanticSearch) {
88 vectorSearch(text).then((res) => {
89 setResponse(res);
90 setQuerying(false);
91 });
92
93 return;
94 }
95
96 search(text).then((res) => {
97 setResponse(res);
98 setQuerying(false);
99 });
100 }, [options, text]);
101
102 useEffect(() => {
103 onSubmit();
104 }, [options.semanticSearch]);
105
106 const handleKeyPress = (event) => {
107 if (event.key === 'Enter') {
108 onSubmit();
109 event.preventDefault();
110 return false;
111 }

Callers

nothing calls this directly

Calls 5

usePilesContextFunction · 0.90
useIndexContextFunction · 0.90
onSubmitFunction · 0.85
filterResultsFunction · 0.85
renderResponseFunction · 0.85

Tested by

no test coverage detected