Showing
1 changed file
with
0 additions
and
68 deletions
src/App.js
deleted
100644 → 0
1 | -import React, {Fragment, useState} from "react"; | ||
2 | -import { Client } from "elasticsearch" | ||
3 | -import "./App.css"; | ||
4 | - | ||
5 | -function App() { | ||
6 | - | ||
7 | - const [answer, setAnswer] = useState(''); | ||
8 | - const [inputValue, setInputValue] = useState(''); | ||
9 | - | ||
10 | - const client = new Client({ | ||
11 | - host: 'http://localhost:9200' | ||
12 | - }); | ||
13 | - | ||
14 | - const onKeyUpHandler = async (event) => { | ||
15 | - if (event.charCode === 13) { | ||
16 | - setInputValue(event.target.value); | ||
17 | - | ||
18 | - if (inputValue !== '' || inputValue !== undefined || inputValue.length !== 0) { | ||
19 | - console.log(inputValue); | ||
20 | - try { | ||
21 | - const result = await client.search({ | ||
22 | - index: "wiki-qna2", | ||
23 | - body: { | ||
24 | - query: { | ||
25 | - match: { | ||
26 | - "질문(원문, 하 난이도)": inputValue | ||
27 | - } | ||
28 | - } | ||
29 | - } | ||
30 | - }); | ||
31 | - | ||
32 | - if (result !== null || result !== undefined || result.length !== 0) { | ||
33 | - setAnswer(result.hits.hits); | ||
34 | - } | ||
35 | - } catch (error) { | ||
36 | - console.log(error); | ||
37 | - } | ||
38 | - } | ||
39 | - } | ||
40 | - } | ||
41 | - | ||
42 | - const showAnswer = (answer) => { | ||
43 | - return ( | ||
44 | - <div> | ||
45 | - <b>{answer !== undefined ? answer._source.정답 : 'loading ....'}</b> | ||
46 | - </div> | ||
47 | - ) | ||
48 | - } | ||
49 | - | ||
50 | - return ( | ||
51 | - <div className="App"> | ||
52 | - <header className="App-header"> | ||
53 | - <Fragment> | ||
54 | - Ask a Question | ||
55 | - <input size="80" onKeyPress={onKeyUpHandler}/> | ||
56 | - <div> | ||
57 | - -- Answers -- | ||
58 | - <div> | ||
59 | - {answer === '' ? " loading answer..." : showAnswer(answer[0])} | ||
60 | - </div> | ||
61 | - </div> | ||
62 | - </Fragment> | ||
63 | - </header> | ||
64 | - </div> | ||
65 | - ); | ||
66 | -} | ||
67 | - | ||
68 | -export default App; |
-
Please register or login to post a comment