Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
foundation1-gcp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Syed Bilal Raees
foundation1-gcp
Commits
101437ec
Commit
101437ec
authored
Jan 03, 2023
by
Muneeb Saeed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Facet API added
parent
ca962a48
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
24 deletions
+76
-24
App.js
nodejs-retail/App.js
+4
-1
credentials.json
nodejs-retail/credentials.json
+0
-0
search-simple-query.js
...mples/interactive-tutorials/search/search-simple-query.js
+7
-7
search-results.css
ulta-beauty/src/components/search-results.css
+4
-0
search-results.js
ulta-beauty/src/components/search-results.js
+53
-12
search.js
ulta-beauty/src/components/search.js
+8
-4
No files found.
nodejs-retail/App.js
View file @
101437ec
...
@@ -11,7 +11,10 @@ app.use(bodyParser.json());
...
@@ -11,7 +11,10 @@ app.use(bodyParser.json());
const
searchService
=
require
(
'./samples/interactive-tutorials/search/search-simple-query'
);
const
searchService
=
require
(
'./samples/interactive-tutorials/search/search-simple-query'
);
app
.
get
(
'/search'
,
(
req
,
res
)
=>
{
app
.
get
(
'/search'
,
(
req
,
res
)
=>
{
searchService
(
req
.
query
.
text
)
const
{
text
,
facets
}
=
req
.
query
const
facetArray
=
facets
&&
facets
.
split
(
','
)
||
[];
const
facetObj
=
facetArray
.
map
((
facet
)
=>
({
facetKey
:
{
key
:
facet
}}));
searchService
(
text
,
facetObj
)
.
then
(
result
=>
{
.
then
(
result
=>
{
return
res
.
send
(
result
);
return
res
.
send
(
result
);
})
})
...
...
nodejs-retail/c
lient_secret_850146903364-offnkcq2ac73ugqlmi7vohoc1rjci312.apps.googleusercontent.com
.json
→
nodejs-retail/c
redentials
.json
View file @
101437ec
File moved
nodejs-retail/samples/interactive-tutorials/search/search-simple-query.js
View file @
101437ec
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
'use strict'
;
'use strict'
;
async
function
main
(
searchQuery
)
{
async
function
main
(
searchQuery
,
facets
,
filters
)
{
// Call Retail API to search for a products in a catalog using only search query.
// Call Retail API to search for a products in a catalog using only search query.
// Imports the Google Cloud client library.
// Imports the Google Cloud client library.
...
@@ -29,7 +29,10 @@ async function main(searchQuery) {
...
@@ -29,7 +29,10 @@ async function main(searchQuery) {
const
placement
=
`projects/
${
projectId
}
/locations/global/catalogs/default_catalog/placements/default_search`
;
const
placement
=
`projects/
${
projectId
}
/locations/global/catalogs/default_catalog/placements/default_search`
;
// Raw search query.
// Raw search query.
const
query
=
searchQuery
;
//TRY DIFFERENT QUERY PHRASES
const
query
=
searchQuery
;
//TRY DIFFERENT QUERY PHRASES
const
facetSpecs
=
facets
?
facets
:
[];
// const filter = filters; // TRY DIFFERENT FILTER EXPRESSIONS
const
filter
=
'(availability: ANY("OUT_OF_STOCK") AND brands: ANY("Google"))'
;
// TRY DIFFERENT FILTER EXPRESSIONS
// A unique identifier for tracking visitors.
// A unique identifier for tracking visitors.
const
visitorId
=
'12345'
;
const
visitorId
=
'12345'
;
...
@@ -44,15 +47,15 @@ async function main(searchQuery) {
...
@@ -44,15 +47,15 @@ async function main(searchQuery) {
};
};
const
callSearch
=
async
()
=>
{
const
callSearch
=
async
()
=>
{
// console.log('Search start');
// Construct request
// Construct request
const
request
=
{
const
request
=
{
placement
,
placement
,
query
,
query
,
facetSpecs
,
// filter,
visitorId
,
visitorId
,
pageSize
,
pageSize
,
};
};
// console.log('Search request: ', request);
// Run request
// Run request
const
response
=
await
retailClient
.
search
(
request
,
{
const
response
=
await
retailClient
.
search
(
request
,
{
...
@@ -60,13 +63,10 @@ async function main(searchQuery) {
...
@@ -60,13 +63,10 @@ async function main(searchQuery) {
});
});
const
searchResponse
=
response
[
IResponseParams
.
ISearchResponse
];
const
searchResponse
=
response
[
IResponseParams
.
ISearchResponse
];
if
(
searchResponse
.
totalSize
===
0
)
{
if
(
searchResponse
.
totalSize
===
0
)
{
console
.
log
(
'The search operation returned no matching results.'
);
return
[];
return
[];
}
else
{
}
else
{
console
.
log
(
'Search result: '
,
JSON
.
stringify
(
searchResponse
,
null
,
4
));
return
JSON
.
stringify
(
searchResponse
,
null
,
4
);
return
JSON
.
stringify
(
searchResponse
,
null
,
4
);
}
}
// console.log('Search end');
};
};
return
callSearch
();
return
callSearch
();
...
...
ulta-beauty/src/components/search-results.css
0 → 100644
View file @
101437ec
.verticalCheckBox
>
.ant-checkbox-wrapper
{
display
:
flex
;
margin-inline-start
:
0
;
}
\ No newline at end of file
ulta-beauty/src/components/search-results.js
View file @
101437ec
import
React
from
'react'
;
import
React
,
{
useState
}
from
'react'
;
import
'./search-results.css'
;
import
{
Typography
,
Col
,
Row
,
Card
,
Select
}
from
'antd'
;
import
{
Typography
,
Col
,
Row
,
Card
,
Select
,
Checkbox
,
Collapse
}
from
'antd'
;
import
{
LinkOutlined
,
FilterFilled
}
from
'@ant-design/icons'
;
import
{
LinkOutlined
,
FilterFilled
}
from
'@ant-design/icons'
;
const
{
Meta
}
=
Card
;
const
{
Meta
}
=
Card
;
const
{
Panel
}
=
Collapse
;
const
SearchResults
=
({
searchResults
})
=>
{
const
SearchResults
=
({
searchResults
,
facets
,
onSelectFacet
})
=>
{
const
availabilityMap
=
new
Map
();
const
availabilityMap
=
new
Map
();
availabilityMap
.
set
(
'IN_STOCK'
,
'In Stock'
);
availabilityMap
.
set
(
'IN_STOCK'
,
'In Stock'
);
availabilityMap
.
set
(
'OUT_OF_STOCK'
,
'Out of Stock'
);
availabilityMap
.
set
(
'OUT_OF_STOCK'
,
'Out of Stock'
);
// const [filters, setFilters] = useState('()');
const
facetOptions
=
[
{
value
:
'brands'
,
label
:
'Brands'
},
{
value
:
'colorFamilies'
,
label
:
'Color Family'
},
{
value
:
'colors'
,
label
:
'Colors'
},
{
value
:
'availability'
,
label
:
'Availability'
}
];
const
facetMap
=
new
Map
();
facetOptions
.
forEach
(
facet
=>
facetMap
.
set
(
facet
.
value
,
facet
.
label
));
const
onChangeHandler
=
(
value
)
=>
{
if
(
value
)
{
onSelectFacet
(
value
)
}
};
const
onChangeCheckboxHandler
=
(
filterValue
,
filterKey
)
=>
{
console
.
log
(
'filterValue'
,
filterValue
);
console
.
log
(
'filterKey'
,
filterKey
);
};
return
(
return
(
<>
<>
{
searchResults
.
length
>
0
&&
{
searchResults
.
length
>
0
&&
...
@@ -27,18 +63,23 @@ const SearchResults = ({ searchResults }) => {
...
@@ -27,18 +63,23 @@ const SearchResults = ({ searchResults }) => {
Add
Facets
to
filter
Add
Facets
to
filter
<
/Typography.Title
>
<
/Typography.Title
>
<
Select
<
Select
defaultValue
=
""
mode
=
"multiple"
allowClear
style
=
{{
width
:
'100%'
}}
style
=
{{
width
:
'100%'
}}
onChange
=
{()
=>
{}}
placeholder
=
"Select facets to filter"
options
=
{[
onChange
=
{(
val
)
=>
onChangeHandler
(
val
)}
{
options
=
{
facetOptions
}
value
:
'hoodie'
,
label
:
'Hoodie'
,
},
]}
/
>
/
>
{
facets
.
length
>
0
&&
facets
.
map
((
facet
,
i
)
=>
<
Collapse
ghost
>
<
Panel
header
=
{
facetMap
.
get
(
facet
.
key
)}
key
=
{
i
}
style
=
{{
fontSize
:
'0.9rem'
,
color
:
'#000000 '
}}
>
<
Checkbox
.
Group
class
=
"verticalCheckBox"
options
=
{[...
facet
.
values
.
map
((
f
)
=>
({
label
:
f
.
value
,
value
:
f
.
value
})
)]}
onChange
=
{(
val
)
=>
onChangeCheckboxHandler
(
val
,
facet
.
key
)}
/
>
<
/Panel
>
<
/Collapse
>
)}
<
/div
>
<
/div
>
<
/Col
>
<
/Col>
<
Col
span
=
{
19
}
>
<
Col
span
=
{
19
}
>
<
Row
>
<
Row
>
{
{
...
...
ulta-beauty/src/components/search.js
View file @
101437ec
...
@@ -8,21 +8,24 @@ const Search = () => {
...
@@ -8,21 +8,24 @@ const Search = () => {
const
[
searchText
,
setSearchText
]
=
useState
({
text
:
''
});
const
[
searchText
,
setSearchText
]
=
useState
({
text
:
''
});
const
[
searchResults
,
setSearchResults
]
=
useState
([]);
const
[
searchResults
,
setSearchResults
]
=
useState
([]);
const
[
facets
,
setfacets
]
=
useState
([]);
const
handleOnChange
=
(
e
)
=>
{
const
handleOnChange
=
(
e
)
=>
{
setSearchText
(
prevState
=>
({
setSearchText
(
prevState
=>
({
...
prevState
,
...
prevState
,
text
:
e
.
target
.
value
text
:
e
.
target
.
value
,
}));
}));
};
};
const
handleOnSearch
=
async
(
value
)
=>
{
const
handleOnSearch
=
async
(
value
)
=>
{
const
{
text
}
=
value
;
const
{
text
,
facets
}
=
value
;
if
(
text
)
{
if
(
text
)
{
const
searchResults
=
await
fetch
(
`http://localhost:3002/search?text=
${
text
}
`
)
const
url
=
`http://localhost:3002/search?text=
${
text
}${
facets
&&
facets
.
length
?
`&facets=
${
facets
}
`
:
''
}
`
;
const
searchResults
=
await
fetch
(
url
)
.
then
(
res
=>
res
.
json
())
.
then
(
res
=>
res
.
json
())
.
catch
(
err
=>
console
.
log
(
err
));
.
catch
(
err
=>
console
.
log
(
err
));
setSearchResults
(
searchResults
.
results
.
length
?
[...
searchResults
.
results
]
:
[]);
setSearchResults
(
searchResults
.
results
.
length
?
[...
searchResults
.
results
]
:
[]);
setfacets
(
searchResults
.
facets
.
length
?
[...
searchResults
.
facets
]
:
[]);
}
}
}
}
...
@@ -32,6 +35,7 @@ const Search = () => {
...
@@ -32,6 +35,7 @@ const Search = () => {
text
:
''
text
:
''
}));
}));
setSearchResults
([]);
setSearchResults
([]);
setfacets
([]);
}
}
return
(
return
(
...
@@ -76,7 +80,7 @@ const Search = () => {
...
@@ -76,7 +80,7 @@ const Search = () => {
<
/Col
>
<
/Col
>
<
/Row
>
<
/Row
>
<
/div
>
<
/div
>
<
SearchResults
searchResults
=
{
searchResults
}
/
>
<
SearchResults
searchResults
=
{
searchResults
}
facets
=
{
facets
}
onSelectFacet
=
{(
val
)
=>
handleOnSearch
({
text
:
searchText
.
text
,
facets
:
val
}
)}
/
>
<
/
>
<
/
>
}
}
{
searchResults
.
length
===
0
&&
{
searchResults
.
length
===
0
&&
...
...
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