Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
GCL_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
안형욱
2021-06-14 01:27:40 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6af7a58a0355b3e1ef6ba30d1972ba8019e4bcb9
6af7a58a
1 parent
35d10318
feat: option 검색 기능 추가
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
14 deletions
frontend/src/components/common/Input.js
frontend/src/lib/api/elasticsearch.js
frontend/src/components/common/Input.js
View file @
6af7a58
...
...
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import
{
TextInput
}
from
'@mantine/core'
;
import
styled
from
'styled-components'
;
import
{
useHistory
,
useLocation
}
from
'react-router-dom'
;
import
{
useDispatch
}
from
'react-redux'
;
import
{
useDispatch
,
useSelector
}
from
'react-redux'
;
import
SearchBox
from
'./SearchBox'
;
import
{
inputColorMap
}
from
'../../lib/styles/palette'
;
import
{
esApi
}
from
'../../lib/api/elasticsearch'
;
...
...
@@ -47,16 +47,27 @@ const MyInput = ({
const
name
=
decodeURIComponent
(
new
URLSearchParams
(
search
).
get
(
'query'
)
||
''
);
const
option
=
decodeURIComponent
(
new
URLSearchParams
(
search
).
get
(
'option'
)
||
''
);
const
dispatch
=
useDispatch
();
const
{
option
:
currentSearchOption
}
=
useSelector
(
state
=>
state
.
searchOption
);
useEffect
(()
=>
{
const
setSearchDatas
=
async
()
=>
{
const
{
results
}
=
await
esApi
.
search
(
name
);
dispatch
(
setParsedDocuments
(
results
));
if
(
option
===
''
)
{
const
{
results
}
=
await
esApi
.
search
(
name
);
dispatch
(
setParsedDocuments
(
results
));
}
else
{
const
{
results
}
=
await
esApi
.
searchWithOption
(
name
,
option
);
dispatch
(
setParsedDocuments
(
results
));
}
};
setQuery
(
name
);
setSearchDatas
();
},
[
name
]);
},
[
name
,
option
]);
return
(
<
InputBlock
...
...
@@ -84,7 +95,13 @@ const MyInput = ({
alert
(
'검색어를 입력 해 주세요.'
);
return
;
}
const
params
=
new
URLSearchParams
({
query
});
const
searchRequest
=
{};
searchRequest
.
query
=
query
;
if
(
currentSearchOption
===
'WRITER'
)
searchRequest
.
option
=
'writer'
;
if
(
currentSearchOption
===
'CONTENT'
)
searchRequest
.
option
=
'content'
;
const
params
=
new
URLSearchParams
(
searchRequest
);
history
.
push
(
`search?
${
decodeURIComponent
(
params
.
toString
())}
`
);
}
}}
...
...
@@ -96,7 +113,13 @@ const MyInput = ({
alert
(
'검색어를 입력 해 주세요.'
);
return
;
}
const
params
=
new
URLSearchParams
({
query
});
const
searchRequest
=
{};
searchRequest
.
query
=
query
;
if
(
currentSearchOption
===
'WRITER'
)
searchRequest
.
option
=
'writer'
;
if
(
currentSearchOption
===
'CONTENT'
)
searchRequest
.
option
=
'content'
;
const
params
=
new
URLSearchParams
(
searchRequest
);
history
.
push
(
`search?
${
decodeURIComponent
(
params
.
toString
())}
`
);
}}
>
...
...
frontend/src/lib/api/elasticsearch.js
View file @
6af7a58
...
...
@@ -19,12 +19,17 @@ export const esApi = {
return
res
.
data
;
},
// searchByFilter: async (filters, searchWord = '') => {
// // const res = await esInstance.post(
// // `/api/as/v1/engines/${process.env.REACT_APP_ENGINE_NAME}/search`,
// // {
// // query: searchWord,
// // }
// // );
// },
searchWithOption
:
async
(
searchWord
,
option
)
=>
{
const
res
=
await
esInstance
.
post
(
`/api/as/v1/engines/
${
process
.
env
.
REACT_APP_ENGINE_NAME
}
/search`
,
{
query
:
searchWord
,
search_fields
:
{
[
option
]:
{},
},
}
);
return
res
.
data
;
},
};
...
...
Please
register
or
login
to post a comment