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
Expand all
Hide whitespace changes
Inline
Side-by-side
client/src/Components/Place.js
View file @
11ea8e32
...
...
@@ -3,9 +3,10 @@ import React, { useEffect, useState } from 'react';
import
{
Modal
,
Container
,
Row
,
Col
,
Button
,
Badge
,
Card
,
Accordion
,
Carousel
}
from
'
react-bootstrap
'
;
function
Place
(
props
)
{
const
[
reviews
,
setReviews
]
=
useState
([])
const
[
reviews
,
setReviews
]
=
useState
()
const
[
db
,
setDb
]
=
useState
(
false
)
const
getReview
=
()
=>
{
axios
.
get
(
`/api/review
/
${
props
.
search
.
name
}
`
)
axios
({
url
:
`/api/review
?keyword=
${
props
.
place
.
name
}
`
,
method
:
'
post
'
,
data
:
{
db
:
db
}
}
)
.
then
(
res
=>
{
console
.
log
(
"
place res.data
"
,
res
.
data
)
setReviews
(
res
.
data
)
...
...
@@ -29,12 +30,12 @@ function Place(props) {
aria
-
labelledby
=
"
example-modal-sizes-title-lg
"
>
<
Modal
.
Header
closeButton
>
<
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.Header
>
<
Modal
.
Body
className
=
"
show-grid
"
>
<
Container
style
=
{{
fontSize
:
'
40px
'
}}
>
{
reviews
.
map
((
review
,
index
)
=>
{
{
Array
.
isArray
(
reviews
)
?
reviews
.
map
((
review
,
index
)
=>
{
return
(
<
Row
className
=
"
mt-4
"
>
<
a
href
=
{
review
.
link
}
>
{
review
.
title
}
<
/a
>
...
...
@@ -42,7 +43,8 @@ function Place(props) {
<
div
>
{
review
.
content
}
<
/div
>
<
/Row
>
)
})}
})
:
"
리뷰가 없습니다.
"
}
<
/Container
>
<
/Modal.Body
>
...
...
client/src/Pages/App.js
View file @
11ea8e32
...
...
@@ -8,10 +8,7 @@ function App() {
const
[
search
,
setSearch
]
=
useState
(
""
);
if
(
state
!==
false
)
{
return
<
Redirect
to
=
{{
pathname
:
`/search/
${
search
}
`
,
state
:
{
id
:
search
},
}}
/>
;
return
<
Redirect
to
=
{
`/search?keyword=
${
search
}
`
}
/>
;
}
const
handleChange
=
(
e
)
=>
{
...
...
client/src/Pages/Search.js
View file @
11ea8e32
...
...
@@ -5,20 +5,20 @@ import Place from '../Components/Place';
import
{
Container
,
Form
,
Row
,
Col
,
Card
,
Image
,
InputGroup
,
FormControl
,
Button
,
Pagination
}
from
'
react-bootstrap
'
;
import
Paginations
from
'
../Components/Paginations
'
;
import
axios
from
'
axios
'
;
import
queryString
from
'
query-string
'
function
Search
(
props
)
{
const
endPage
=
10
;
const
[
state
,
setState
]
=
useState
(
false
);
const
[
index
,
setIndex
]
=
useState
(
1
);
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
[
place
,
setPlace
]
=
useState
([{
name
:
""
,
category
:
""
,
address
:
""
}])
const
[
imgUrl
,
setImgUrl
]
=
useState
([])
const
[
association
,
setAssociation
]
=
useState
([])
const
getImg
=
()
=>
{
axios
.
get
(
`/api/search/imges
/
${
search
}
`
)
axios
.
get
(
`/api/search/imges
?keyword=
${
search
}
`
)
.
then
(
res
=>
{
console
.
log
(
"
images=
"
,
res
.
data
)
setImgUrl
(
res
.
data
)
...
...
@@ -29,7 +29,7 @@ function Search(props) {
}
const
getPlace
=
()
=>
{
axios
.
get
(
`/api/search/places
/
${
search
}
`
)
axios
.
get
(
`/api/search/places
?keyword=
${
search
}
`
)
.
then
(
res
=>
{
console
.
log
(
"
places=
"
,
res
.
data
)
setPlace
(
res
.
data
)
...
...
@@ -40,7 +40,7 @@ function Search(props) {
}
const
getAssociation
=
()
=>
{
axios
.
get
(
`/api/search/association
/
${
search
}
`
)
axios
.
get
(
`/api/search/association
?keyword=
${
search
}
`
)
.
then
(
res
=>
{
console
.
log
(
"
Associations =
"
,
res
.
data
)
setAssociation
(
res
.
data
)
...
...
@@ -92,7 +92,7 @@ function Search(props) {
if
(
state
!==
false
)
{
return
<
Redirect
to
=
{{
pathname
:
`/search
/
${
search
}
`
,
pathname
:
`/search
?keyword=
${
search
}
`
,
state
:
{
id
:
search
},
}}
/>
;
}
...
...
client/src/index.js
View file @
11ea8e32
...
...
@@ -13,17 +13,13 @@ import {
Redirect
,
}
from
"
react-router-dom
"
;
axios
.
defaults
.
validateStatus
=
function
(
status
)
{
return
status
<
500
;
// default
}
ReactDOM
.
render
(
<
React
.
StrictMode
>
<
Router
>
<
Switch
>
<
Route
exact
path
=
"
/
"
component
=
{
App
}
/
>
<
Route
path
=
"
/search
"
component
=
{
Search
}
/
>
<
Redirect
path
=
"
/search
/:search
"
to
=
"
/search
"
/>
<
Redirect
path
=
"
/search
"
to
=
"
/search
"
/>
<
/Switch
>
<
/Router
>
<
/React.StrictMode>
,
...
...
googleReview
View file @
11ea8e32
This diff is collapsed.
Click to expand it.
server/controllers/place.controller.js
View file @
11ea8e32
...
...
@@ -6,7 +6,7 @@ import { time } from 'console';
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
axios
.
get
(
url
)
.
then
(
async
(
response
)
=>
{
...
...
@@ -35,12 +35,12 @@ const searchPlace = 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
)
.
then
(
async
(
response
)
=>
{
const
html
=
response
.
data
let
name
=
req
.
params
.
search
let
name
=
req
.
query
.
keyword
let
$1
=
cheerio
.
load
(
html
);
let
images
=
$1
(
'
.RAyV4b
'
).
find
(
'
img
'
).
attr
(
'
src
'
)
...
...
@@ -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
())
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
(
).
save
()
...
...
@@ -68,15 +68,19 @@ const searchImg = async (req, res) => {
}
const
searchAssociation
=
async
(
req
,
res
)
=>
{
let
Place
=
await
Places
.
findOne
({
name
:
req
.
params
.
search
})
let
address
=
Place
.
address
.
split
(
'
'
)[
0
]
let
Place
=
await
Places
.
findOne
({
name
:
req
.
query
.
keyword
})
if
(
!
Place
)
{
res
.
send
([])
}
let
addresse
=
Place
.
address
.
split
(
'
'
)[
0
]
// let AssociationsId = []
let
addressPlaces
=
new
RegExp
(
`
${
address
}
`
)
let
addressPlaces
=
new
RegExp
(
`
${
address
e
}
`
)
let
responsePlaces
=
await
Places
.
find
({
address
:
addressPlaces
})
res
.
send
(
responsePlaces
)
// responsePlaces.map(Association => {
// AssociationsId.push(Association._id)
// })
...
...
server/controllers/review.controller.js
View file @
11ea8e32
import
Review
from
'
../models/Review.js
'
import
cheerio
from
"
cheerio
"
;
import
iconv
from
'
iconv
'
import
fs
from
'
fs
'
import
axios
from
'
axios
'
;
const
Iconv
=
iconv
.
Iconv
const
search
=
async
(
req
,
res
,
next
)
=>
{
try
{
let
reviews
=
[]
let
content
=
[]
Review
.
find
()
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site%3Atistory.com&page_no=1
"
const
response1
=
await
axios
.
get
(
url
)
// console.log(response1.data)
const
$1
=
cheerio
.
load
(
response1
.
data
);
$1
(
'
.kCrYT
'
).
each
(
async
function
(
i
)
{
const
title
=
$1
(
this
).
find
(
'
h3
'
).
text
()
const
searchParams
=
new
URLSearchParams
(
$1
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
));
const
link
=
searchParams
.
get
(
"
/url?q
"
)
const
summary
=
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
()
content
.
push
(
getReview
(
link
))
if
(
title
)
{
reviews
[
i
]
=
{
title
:
title
,
link
:
link
}
}
else
if
(
summary
)
{
reviews
[
i
-
1
]
=
{
...
reviews
[
i
-
1
],
summary
:
summary
}
reviews
=
reviews
.
filter
(
e
=>
e
)
}
})
let
promiseReview
=
await
Promise
.
all
(
content
)
promiseReview
=
promiseReview
.
filter
(
e
=>
typeof
(
e
)
===
'
string
'
)
reviews
.
forEach
(
async
(
review
,
i
)
=>
{
review
[
"
content
"
]
=
promiseReview
[
i
]
const
reviews
=
new
Review
(
review
).
save
()
})
res
.
send
(
reviews
)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
send
(
error
)
console
.
log
(
"
1
"
)
for
(
let
i
=
1
;
(
req
.
reviews
).
length
>
10
;
i
++
)
{
try
{
console
.
log
(
"
2
"
)
let
reviews
=
[]
let
content
=
[]
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
query
.
keyword
)
+
"
+site%3Atistory.com&page_no=
"
+
i
const
response1
=
await
axios
.
get
(
url
)
// console.log(response1.data)
const
$1
=
cheerio
.
load
(
response1
.
data
);
$1
(
'
.kCrYT
'
).
each
(
async
function
(
i
)
{
console
.
log
(
"
3
"
)
const
title
=
$1
(
this
).
find
(
'
h3
'
).
text
()
const
searchParams
=
new
URLSearchParams
(
$1
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
));
const
link
=
searchParams
.
get
(
"
/url?q
"
)
const
summary
=
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
()
Review
.
find
({
link
:
link
},
function
(
err
,
review
)
{
if
(
!
review
)
{
content
.
push
(
getReview
(
link
))
if
(
title
)
{
reviews
[
i
]
=
{
title
:
title
,
link
:
link
}
}
else
if
(
summary
)
{
reviews
[
i
-
1
]
=
{
...
reviews
[
i
-
1
],
summary
:
summary
}
reviews
=
reviews
.
filter
(
e
=>
e
)
}
}
})
})
let
promiseReview
=
await
Promise
.
all
(
content
)
promiseReview
=
promiseReview
.
filter
(
e
=>
typeof
(
e
)
===
'
string
'
)
reviews
.
forEach
(
async
(
review
,
i
)
=>
{
console
.
log
(
"
4
"
)
review
[
"
content
"
]
=
promiseReview
[
i
]
const
reviews
=
new
Review
(
review
).
save
()
reviews
.
keyword
.
push
(
req
.
query
.
keyword
)
req
.
reviews
.
push
(
reviews
)
})
console
.
log
(
"
5
"
)
res
.
send
(
reviews
)
}
catch
(
error
)
{
console
.
log
(
"
6
"
)
console
.
log
(
error
)
res
.
send
(
error
)
}
}
}
...
...
@@ -71,8 +80,18 @@ const getReview = async (link) => {
}
}
const
find
=
(
res
,
req
,
next
)
=>
{
Review
.
find
({
address
:
})
const
find
=
(
req
,
res
,
next
)
=>
{
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
}
\ 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'
const
router
=
express
.
Router
()
router
.
route
(
'
/api/search/imges
/:search
'
)
router
.
route
(
'
/api/search/imges
'
)
.
get
(
place
.
searchImg
)
router
.
route
(
'
/api/search/places
/:search
'
)
router
.
route
(
'
/api/search/places
'
)
.
get
(
place
.
searchPlace
)
router
.
route
(
'
/api/search/association
/:search
'
)
router
.
route
(
'
/api/search/association
'
)
.
get
(
place
.
searchAssociation
)
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'
const
router
=
express
.
Router
()
router
.
route
(
'
/api/review
/:search
'
)
.
get
(
review
.
search
)
router
.
route
(
'
/api/review
'
)
.
post
(
review
.
find
,
review
.
search
)
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