Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
search-page
Commits
11ea8e32
Commit
11ea8e32
authored
Jan 24, 2021
by
Kim, Chaerin
Browse files
쿼리스트링
parent
768b5382
Changes
9
Show whitespace changes
Inline
Side-by-side
client/src/Components/Place.js
View file @
11ea8e32
...
@@ -3,9 +3,10 @@ import React, { useEffect, useState } from 'react';
...
@@ -3,9 +3,10 @@ import React, { useEffect, useState } from 'react';
import
{
Modal
,
Container
,
Row
,
Col
,
Button
,
Badge
,
Card
,
Accordion
,
Carousel
}
from
'
react-bootstrap
'
;
import
{
Modal
,
Container
,
Row
,
Col
,
Button
,
Badge
,
Card
,
Accordion
,
Carousel
}
from
'
react-bootstrap
'
;
function
Place
(
props
)
{
function
Place
(
props
)
{
const
[
reviews
,
setReviews
]
=
useState
([])
const
[
reviews
,
setReviews
]
=
useState
()
const
[
db
,
setDb
]
=
useState
(
false
)
const
getReview
=
()
=>
{
const
getReview
=
()
=>
{
axios
.
get
(
`/api/review
/
${
props
.
search
.
name
}
`
)
axios
({
url
:
`/api/review
?keyword=
${
props
.
place
.
name
}
`
,
method
:
'
post
'
,
data
:
{
db
:
db
}
}
)
.
then
(
res
=>
{
.
then
(
res
=>
{
console
.
log
(
"
place res.data
"
,
res
.
data
)
console
.
log
(
"
place res.data
"
,
res
.
data
)
setReviews
(
res
.
data
)
setReviews
(
res
.
data
)
...
@@ -29,12 +30,12 @@ function Place(props) {
...
@@ -29,12 +30,12 @@ function Place(props) {
aria
-
labelledby
=
"
example-modal-sizes-title-lg
"
>
aria
-
labelledby
=
"
example-modal-sizes-title-lg
"
>
<
Modal
.
Header
closeButton
>
<
Modal
.
Header
closeButton
>
<
Modal
.
Title
id
=
"
contained-modal-title-vcenter
"
style
=
{{
fontSize
:
'
40px
'
}}
>
<
Modal
.
Title
id
=
"
contained-modal-title-vcenter
"
style
=
{{
fontSize
:
'
40px
'
}}
>
{
props
.
index
+
1
}.
{
props
.
search
.
name
}
{
props
.
index
+
1
}.
{
props
.
place
.
name
}
<
/Modal.Title
>
<
/Modal.Title
>
<
/Modal.Header
>
<
/Modal.Header
>
<
Modal
.
Body
className
=
"
show-grid
"
>
<
Modal
.
Body
className
=
"
show-grid
"
>
<
Container
style
=
{{
fontSize
:
'
40px
'
}}
>
<
Container
style
=
{{
fontSize
:
'
40px
'
}}
>
{
reviews
.
map
((
review
,
index
)
=>
{
{
Array
.
isArray
(
reviews
)
?
reviews
.
map
((
review
,
index
)
=>
{
return
(
return
(
<
Row
className
=
"
mt-4
"
>
<
Row
className
=
"
mt-4
"
>
<
a
href
=
{
review
.
link
}
>
{
review
.
title
}
<
/a
>
<
a
href
=
{
review
.
link
}
>
{
review
.
title
}
<
/a
>
...
@@ -42,7 +43,8 @@ function Place(props) {
...
@@ -42,7 +43,8 @@ function Place(props) {
<
div
>
{
review
.
content
}
<
/div
>
<
div
>
{
review
.
content
}
<
/div
>
<
/Row
>
<
/Row
>
)
)
})}
})
:
"
리뷰가 없습니다.
"
}
<
/Container
>
<
/Container
>
<
/Modal.Body
>
<
/Modal.Body
>
...
...
client/src/Pages/App.js
View file @
11ea8e32
...
@@ -8,10 +8,7 @@ function App() {
...
@@ -8,10 +8,7 @@ function App() {
const
[
search
,
setSearch
]
=
useState
(
""
);
const
[
search
,
setSearch
]
=
useState
(
""
);
if
(
state
!==
false
)
{
if
(
state
!==
false
)
{
return
<
Redirect
to
=
{{
return
<
Redirect
to
=
{
`/search?keyword=
${
search
}
`
}
/>
;
pathname
:
`/search/
${
search
}
`
,
state
:
{
id
:
search
},
}}
/>
;
}
}
const
handleChange
=
(
e
)
=>
{
const
handleChange
=
(
e
)
=>
{
...
...
client/src/Pages/Search.js
View file @
11ea8e32
...
@@ -5,20 +5,20 @@ import Place from '../Components/Place';
...
@@ -5,20 +5,20 @@ import Place from '../Components/Place';
import
{
Container
,
Form
,
Row
,
Col
,
Card
,
Image
,
InputGroup
,
FormControl
,
Button
,
Pagination
}
from
'
react-bootstrap
'
;
import
{
Container
,
Form
,
Row
,
Col
,
Card
,
Image
,
InputGroup
,
FormControl
,
Button
,
Pagination
}
from
'
react-bootstrap
'
;
import
Paginations
from
'
../Components/Paginations
'
;
import
Paginations
from
'
../Components/Paginations
'
;
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
import
queryString
from
'
query-string
'
function
Search
(
props
)
{
function
Search
(
props
)
{
const
endPage
=
10
;
const
endPage
=
10
;
const
[
state
,
setState
]
=
useState
(
false
);
const
[
state
,
setState
]
=
useState
(
false
);
const
[
index
,
setIndex
]
=
useState
(
1
);
const
[
index
,
setIndex
]
=
useState
(
1
);
const
[
showSet
,
setShowSet
]
=
useState
([
false
,
false
,
false
,
false
]);
const
[
showSet
,
setShowSet
]
=
useState
([
false
,
false
,
false
,
false
]);
const
[
search
,
setSearch
]
=
useState
(
props
.
location
.
s
tate
.
i
d
);
const
[
search
,
setSearch
]
=
useState
(
queryString
.
parse
(
props
.
location
.
s
earch
).
keywor
d
);
const
[
mobile
,
setMobile
]
=
useState
();
const
[
mobile
,
setMobile
]
=
useState
();
const
[
place
,
setPlace
]
=
useState
([{
name
:
""
,
category
:
""
,
address
:
""
}])
const
[
place
,
setPlace
]
=
useState
([{
name
:
""
,
category
:
""
,
address
:
""
}])
const
[
imgUrl
,
setImgUrl
]
=
useState
([])
const
[
imgUrl
,
setImgUrl
]
=
useState
([])
const
[
association
,
setAssociation
]
=
useState
([])
const
[
association
,
setAssociation
]
=
useState
([])
const
getImg
=
()
=>
{
const
getImg
=
()
=>
{
axios
.
get
(
`/api/search/imges
/
${
search
}
`
)
axios
.
get
(
`/api/search/imges
?keyword=
${
search
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
console
.
log
(
"
images=
"
,
res
.
data
)
console
.
log
(
"
images=
"
,
res
.
data
)
setImgUrl
(
res
.
data
)
setImgUrl
(
res
.
data
)
...
@@ -29,7 +29,7 @@ function Search(props) {
...
@@ -29,7 +29,7 @@ function Search(props) {
}
}
const
getPlace
=
()
=>
{
const
getPlace
=
()
=>
{
axios
.
get
(
`/api/search/places
/
${
search
}
`
)
axios
.
get
(
`/api/search/places
?keyword=
${
search
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
console
.
log
(
"
places=
"
,
res
.
data
)
console
.
log
(
"
places=
"
,
res
.
data
)
setPlace
(
res
.
data
)
setPlace
(
res
.
data
)
...
@@ -40,7 +40,7 @@ function Search(props) {
...
@@ -40,7 +40,7 @@ function Search(props) {
}
}
const
getAssociation
=
()
=>
{
const
getAssociation
=
()
=>
{
axios
.
get
(
`/api/search/association
/
${
search
}
`
)
axios
.
get
(
`/api/search/association
?keyword=
${
search
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
console
.
log
(
"
Associations =
"
,
res
.
data
)
console
.
log
(
"
Associations =
"
,
res
.
data
)
setAssociation
(
res
.
data
)
setAssociation
(
res
.
data
)
...
@@ -92,7 +92,7 @@ function Search(props) {
...
@@ -92,7 +92,7 @@ function Search(props) {
if
(
state
!==
false
)
{
if
(
state
!==
false
)
{
return
<
Redirect
to
=
{{
return
<
Redirect
to
=
{{
pathname
:
`/search
/
${
search
}
`
,
pathname
:
`/search
?keyword=
${
search
}
`
,
state
:
{
id
:
search
},
state
:
{
id
:
search
},
}}
/>
;
}}
/>
;
}
}
...
...
client/src/index.js
View file @
11ea8e32
...
@@ -13,17 +13,13 @@ import {
...
@@ -13,17 +13,13 @@ import {
Redirect
,
Redirect
,
}
from
"
react-router-dom
"
;
}
from
"
react-router-dom
"
;
axios
.
defaults
.
validateStatus
=
function
(
status
)
{
return
status
<
500
;
// default
}
ReactDOM
.
render
(
ReactDOM
.
render
(
<
React
.
StrictMode
>
<
React
.
StrictMode
>
<
Router
>
<
Router
>
<
Switch
>
<
Switch
>
<
Route
exact
path
=
"
/
"
component
=
{
App
}
/
>
<
Route
exact
path
=
"
/
"
component
=
{
App
}
/
>
<
Route
path
=
"
/search
"
component
=
{
Search
}
/
>
<
Route
path
=
"
/search
"
component
=
{
Search
}
/
>
<
Redirect
path
=
"
/search
/:search
"
to
=
"
/search
"
/>
<
Redirect
path
=
"
/search
"
to
=
"
/search
"
/>
<
/Switch
>
<
/Switch
>
<
/Router
>
<
/Router
>
<
/React.StrictMode>
,
<
/React.StrictMode>
,
...
...
googleReview
View file @
11ea8e32
This source diff could not be displayed because it is too large. You can
view the blob
instead.
server/controllers/place.controller.js
View file @
11ea8e32
...
@@ -6,7 +6,7 @@ import { time } from 'console';
...
@@ -6,7 +6,7 @@ import { time } from 'console';
const
searchPlace
=
async
(
req
,
res
)
=>
{
const
searchPlace
=
async
(
req
,
res
)
=>
{
const
url
=
"
https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=
"
+
encodeURI
(
req
.
params
.
search
)
const
url
=
"
https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=
"
+
encodeURI
(
req
.
query
.
keyword
)
const
editUrl
=
/
(
http
(
s
)?
:
\/\/)([
a-z0-9
\w]
+
\.
*
)
+
[
a-z0-9
]{2,4}
/gi
const
editUrl
=
/
(
http
(
s
)?
:
\/\/)([
a-z0-9
\w]
+
\.
*
)
+
[
a-z0-9
]{2,4}
/gi
axios
.
get
(
url
)
axios
.
get
(
url
)
.
then
(
async
(
response
)
=>
{
.
then
(
async
(
response
)
=>
{
...
@@ -35,12 +35,12 @@ const searchPlace = async (req, res) => {
...
@@ -35,12 +35,12 @@ const searchPlace = async (req, res) => {
}
}
const
searchImg
=
async
(
req
,
res
)
=>
{
const
searchImg
=
async
(
req
,
res
)
=>
{
const
imgUrl
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch
"
const
imgUrl
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
query
.
keyword
)
+
"
+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch
"
axios
.
get
(
imgUrl
)
axios
.
get
(
imgUrl
)
.
then
(
async
(
response
)
=>
{
.
then
(
async
(
response
)
=>
{
const
html
=
response
.
data
const
html
=
response
.
data
let
name
=
req
.
params
.
search
let
name
=
req
.
query
.
keyword
let
$1
=
cheerio
.
load
(
html
);
let
$1
=
cheerio
.
load
(
html
);
let
images
=
$1
(
'
.RAyV4b
'
).
find
(
'
img
'
).
attr
(
'
src
'
)
let
images
=
$1
(
'
.RAyV4b
'
).
find
(
'
img
'
).
attr
(
'
src
'
)
...
@@ -55,9 +55,9 @@ const searchImg = async (req, res) => {
...
@@ -55,9 +55,9 @@ const searchImg = async (req, res) => {
// 여기서 있는건 찾아와서 추가를 시켜야한다.
// 여기서 있는건 찾아와서 추가를 시켜야한다.
//사진만 업데이트
//사진만 업데이트
let
Place
=
await
Places
.
findOne
({
name
:
req
.
params
.
search
})
let
Place
=
await
Places
.
findOne
({
name
:
req
.
query
.
keyword
})
Place
.
times
.
push
(
new
Date
().
toLocaleString
())
Place
.
times
.
push
(
new
Date
().
toLocaleString
())
await
Places
.
updateOne
({
name
:
req
.
params
.
search
},
{
img
:
images
,
times
:
Place
.
times
})
await
Places
.
updateOne
({
name
:
req
.
query
.
keyword
},
{
img
:
images
,
times
:
Place
.
times
})
const
newPlaces
=
await
new
Places
(
const
newPlaces
=
await
new
Places
(
).
save
()
).
save
()
...
@@ -68,15 +68,19 @@ const searchImg = async (req, res) => {
...
@@ -68,15 +68,19 @@ const searchImg = async (req, res) => {
}
}
const
searchAssociation
=
async
(
req
,
res
)
=>
{
const
searchAssociation
=
async
(
req
,
res
)
=>
{
let
Place
=
await
Places
.
findOne
({
name
:
req
.
params
.
search
})
let
Place
=
await
Places
.
findOne
({
name
:
req
.
query
.
keyword
})
let
address
=
Place
.
address
.
split
(
'
'
)[
0
]
if
(
!
Place
)
{
res
.
send
([])
}
let
addresse
=
Place
.
address
.
split
(
'
'
)[
0
]
// let AssociationsId = []
// let AssociationsId = []
let
addressPlaces
=
new
RegExp
(
`
${
address
}
`
)
let
addressPlaces
=
new
RegExp
(
`
${
address
e
}
`
)
let
responsePlaces
=
await
Places
.
find
({
address
:
addressPlaces
})
let
responsePlaces
=
await
Places
.
find
({
address
:
addressPlaces
})
res
.
send
(
responsePlaces
)
res
.
send
(
responsePlaces
)
// responsePlaces.map(Association => {
// responsePlaces.map(Association => {
// AssociationsId.push(Association._id)
// AssociationsId.push(Association._id)
// })
// })
...
...
server/controllers/review.controller.js
View file @
11ea8e32
import
Review
from
'
../models/Review.js
'
import
Review
from
'
../models/Review.js
'
import
cheerio
from
"
cheerio
"
;
import
cheerio
from
"
cheerio
"
;
import
iconv
from
'
iconv
'
import
fs
from
'
fs
'
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
const
Iconv
=
iconv
.
Iconv
const
search
=
async
(
req
,
res
,
next
)
=>
{
const
search
=
async
(
req
,
res
,
next
)
=>
{
console
.
log
(
"
1
"
)
for
(
let
i
=
1
;
(
req
.
reviews
).
length
>
10
;
i
++
)
{
try
{
try
{
console
.
log
(
"
2
"
)
let
reviews
=
[]
let
reviews
=
[]
let
content
=
[]
let
content
=
[]
Review
.
find
()
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
query
.
keyword
)
+
"
+site%3Atistory.com&page_no=
"
+
i
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site%3Atistory.com&page_no=1
"
const
response1
=
await
axios
.
get
(
url
)
const
response1
=
await
axios
.
get
(
url
)
// console.log(response1.data)
// console.log(response1.data)
const
$1
=
cheerio
.
load
(
response1
.
data
);
const
$1
=
cheerio
.
load
(
response1
.
data
);
$1
(
'
.kCrYT
'
).
each
(
async
function
(
i
)
{
$1
(
'
.kCrYT
'
).
each
(
async
function
(
i
)
{
console
.
log
(
"
3
"
)
const
title
=
$1
(
this
).
find
(
'
h3
'
).
text
()
const
title
=
$1
(
this
).
find
(
'
h3
'
).
text
()
const
searchParams
=
new
URLSearchParams
(
$1
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
));
const
searchParams
=
new
URLSearchParams
(
$1
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
));
const
link
=
searchParams
.
get
(
"
/url?q
"
)
const
link
=
searchParams
.
get
(
"
/url?q
"
)
const
summary
=
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
()
const
summary
=
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
()
Review
.
find
({
link
:
link
},
function
(
err
,
review
)
{
if
(
!
review
)
{
content
.
push
(
getReview
(
link
))
content
.
push
(
getReview
(
link
))
if
(
title
)
{
if
(
title
)
{
reviews
[
i
]
=
{
title
:
title
,
link
:
link
}
reviews
[
i
]
=
{
title
:
title
,
link
:
link
}
...
@@ -26,19 +28,26 @@ const search = async (req, res, next) => {
...
@@ -26,19 +28,26 @@ const search = async (req, res, next) => {
reviews
[
i
-
1
]
=
{
...
reviews
[
i
-
1
],
summary
:
summary
}
reviews
[
i
-
1
]
=
{
...
reviews
[
i
-
1
],
summary
:
summary
}
reviews
=
reviews
.
filter
(
e
=>
e
)
reviews
=
reviews
.
filter
(
e
=>
e
)
}
}
}
})
})
})
let
promiseReview
=
await
Promise
.
all
(
content
)
let
promiseReview
=
await
Promise
.
all
(
content
)
promiseReview
=
promiseReview
.
filter
(
e
=>
typeof
(
e
)
===
'
string
'
)
promiseReview
=
promiseReview
.
filter
(
e
=>
typeof
(
e
)
===
'
string
'
)
reviews
.
forEach
(
async
(
review
,
i
)
=>
{
reviews
.
forEach
(
async
(
review
,
i
)
=>
{
console
.
log
(
"
4
"
)
review
[
"
content
"
]
=
promiseReview
[
i
]
review
[
"
content
"
]
=
promiseReview
[
i
]
const
reviews
=
new
Review
(
review
).
save
()
const
reviews
=
new
Review
(
review
).
save
()
reviews
.
keyword
.
push
(
req
.
query
.
keyword
)
req
.
reviews
.
push
(
reviews
)
})
})
console
.
log
(
"
5
"
)
res
.
send
(
reviews
)
res
.
send
(
reviews
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
"
6
"
)
console
.
log
(
error
)
console
.
log
(
error
)
res
.
send
(
error
)
res
.
send
(
error
)
}
}
}
}
}
//***************네이버 크롤링 할 때 ********************* */
//***************네이버 크롤링 할 때 ********************* */
...
@@ -71,8 +80,18 @@ const getReview = async (link) => {
...
@@ -71,8 +80,18 @@ const getReview = async (link) => {
}
}
}
}
const
find
=
(
res
,
req
,
next
)
=>
{
const
find
=
(
req
,
res
,
next
)
=>
{
Review
.
find
({
address
:
})
console
.
log
(
"
7
"
,
req
.
body
)
if
(
req
.
body
.
db
)
{
next
()
}
Review
.
find
({
keyword
:{
$elemMatch
:
res
.
query
.
keyword
}
},
function
(
err
,
reviews
)
{
if
(
reviews
)
{
if
(
reviews
.
length
>
10
)
res
.
send
(
reviews
,
{
db
:
true
})
req
.
reviews
=
reviews
}
next
()
})
}
}
export
default
{
search
,
find
}
export
default
{
search
,
find
}
\ No newline at end of file
server/routes/place.routes.js
View file @
11ea8e32
...
@@ -3,13 +3,13 @@ import place from '../controllers/place.controller.js'
...
@@ -3,13 +3,13 @@ import place from '../controllers/place.controller.js'
const
router
=
express
.
Router
()
const
router
=
express
.
Router
()
router
.
route
(
'
/api/search/imges
/:search
'
)
router
.
route
(
'
/api/search/imges
'
)
.
get
(
place
.
searchImg
)
.
get
(
place
.
searchImg
)
router
.
route
(
'
/api/search/places
/:search
'
)
router
.
route
(
'
/api/search/places
'
)
.
get
(
place
.
searchPlace
)
.
get
(
place
.
searchPlace
)
router
.
route
(
'
/api/search/association
/:search
'
)
router
.
route
(
'
/api/search/association
'
)
.
get
(
place
.
searchAssociation
)
.
get
(
place
.
searchAssociation
)
export
default
router
export
default
router
\ No newline at end of file
server/routes/review.routes.js
View file @
11ea8e32
...
@@ -3,7 +3,7 @@ import review from '../controllers/review.controller.js'
...
@@ -3,7 +3,7 @@ import review from '../controllers/review.controller.js'
const
router
=
express
.
Router
()
const
router
=
express
.
Router
()
router
.
route
(
'
/api/review
/:search
'
)
router
.
route
(
'
/api/review
'
)
.
get
(
review
.
search
)
.
post
(
review
.
find
,
review
.
search
)
export
default
router
export
default
router
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment