Skip to content

Commit

Permalink
fix: suggestions api url (#1273)
Browse files Browse the repository at this point in the history
## What's the purpose of this pull request?
After the PR of using the new search api, the suggestions stopped working, this PR is premised on fixing this issue.
  • Loading branch information
emersonlaurentino authored May 6, 2022
1 parent a3f0f3c commit 6f8a961
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
12 changes: 8 additions & 4 deletions packages/api/src/platforms/vtex/clients/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fetchAPI } from '../fetch'
import type { FacetSearchResult } from './types/FacetSearchResult'
import type {
ProductSearchResult,
SuggestedTerms,
Suggestion,
} from './types/ProductSearchResult'

export type Sort =
Expand Down Expand Up @@ -90,12 +90,16 @@ export const IntelligentSearch = (
const suggestedProducts = (
args: Omit<SearchArgs, 'type'>
): Promise<ProductSearchResult> =>
fetchAPI(`${base}/api/suggestion_products/?term=${args.query}`)
fetchAPI(
`${base}/_v/api/intelligent-search/product_search?query=${args.query}`
)

const suggestedTerms = (
args: Omit<SearchArgs, 'type'>
): Promise<SuggestedTerms> =>
fetchAPI(`${base}/api/split/suggestion_search/?q=${args.query}`)
): Promise<Suggestion> =>
fetchAPI(
`${base}/_v/api/intelligent-search/search_suggestions?query=${args.query}`
)

const facets = (args: Omit<SearchArgs, 'type'>) =>
search<FacetSearchResult>({ ...args, type: 'facets' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,6 @@ export interface First {
index: number
}

export interface SuggestedTerms {
total: number
sampling: boolean
translated: boolean
locale: string
query: string
operator: string
suggestion: Suggestion
correction: Correction
}

export interface Suggestion {
searches: Search[]
}
Expand Down
4 changes: 1 addition & 3 deletions packages/api/src/platforms/vtex/resolvers/searchResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export const StoreSearchResult: Record<string, Resolver<Root>> = {
})
.filter((sku) => !!sku)

const {
suggestion: { searches },
} = terms
const { searches } = terms

return {
terms: searches.map((item) => item.term),
Expand Down
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3622,7 +3622,7 @@
"@docsearch/css" "3.0.0"
algoliasearch "^4.0.0"

"@docusaurus/core@2.0.0-beta.17", "@docusaurus/core@^2.0.0-beta.17":
"@docusaurus/core@2.0.0-beta.17":
version "2.0.0-beta.17"
resolved "https://registry.yarnpkg.com/@docusaurus/core/-/core-2.0.0-beta.17.tgz#f631aae04405de42a428a31928998242cd1d7b77"
integrity sha512-iNdW7CsmHNOgc4PxD9BFxa+MD8+i7ln7erOBkF3FSMMPnsKUeVqsR3rr31aLmLZRlTXMITSPLxlXwtBZa3KPCw==
Expand Down Expand Up @@ -3848,7 +3848,7 @@
sitemap "^7.1.1"
tslib "^2.3.1"

"@docusaurus/preset-classic@^2.0.0-beta.17":
"@docusaurus/preset-classic@2.0.0-beta.17":
version "2.0.0-beta.17"
resolved "https://registry.yarnpkg.com/@docusaurus/preset-classic/-/preset-classic-2.0.0-beta.17.tgz#a8fc3447aa6fe0e5f259d894cc8dd64c049c7605"
integrity sha512-7YUxPEgM09aZWr25/hpDEp1gPl+1KsCPV1ZTRW43sbQ9TinPm+9AKR3rHVDa8ea8MdiS7BpqCVyK+H/eiyQrUw==
Expand All @@ -3873,7 +3873,7 @@
"@types/react" "*"
prop-types "^15.6.2"

"@docusaurus/remark-plugin-npm2yarn@^2.0.0-beta.17":
"@docusaurus/remark-plugin-npm2yarn@2.0.0-beta.17":
version "2.0.0-beta.17"
resolved "https://registry.yarnpkg.com/@docusaurus/remark-plugin-npm2yarn/-/remark-plugin-npm2yarn-2.0.0-beta.17.tgz#7d94d7240d9e2789c04ad5e871c7d3b5fc283632"
integrity sha512-5GqAoIc8PJ7t4z87ftxeEpSEeHdTd3SOaR9DqeVWb7SuMar/mE2pgP/RuJc+5+Oow2aR34Tc4ufKw8vwwr/TnQ==
Expand Down Expand Up @@ -3922,7 +3922,7 @@
tslib "^2.3.1"
utility-types "^3.10.0"

"@docusaurus/theme-live-codeblock@^2.0.0-beta.17":
"@docusaurus/theme-live-codeblock@2.0.0-beta.17":
version "2.0.0-beta.17"
resolved "https://registry.yarnpkg.com/@docusaurus/theme-live-codeblock/-/theme-live-codeblock-2.0.0-beta.17.tgz#66c4f802e890cbf9b91bee6b54a3cf09ba2be6fd"
integrity sha512-fz4LkQaHbuCXKBLNJogXHbnvFoMlM4IgW4m2pmg2jqAbEn8QKIB1XrRLXBuS5QPt5Ys1cYUEtKW01Yf0NhpJZQ==
Expand Down Expand Up @@ -22681,6 +22681,11 @@ react-fast-compare@^3.0.1, react-fast-compare@^3.2.0:
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.0.tgz#641a9da81b6a6320f270e89724fb45a0b39e43bb"
integrity sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==

react-ga4@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/react-ga4/-/react-ga4-1.4.1.tgz#6ee2a2db115ed235b2f2092bc746b4eeeca9e206"
integrity sha512-ioBMEIxd4ePw4YtaloTUgqhQGqz5ebDdC4slEpLgy2sLx1LuZBC9iYCwDymTXzcntw6K1dHX183ulP32nNdG7w==

react-helmet-async@*, react-helmet-async@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/react-helmet-async/-/react-helmet-async-1.2.3.tgz#57326a69304ea3293036eafb49475e9ba454cb37"
Expand Down

1 comment on commit 6f8a961

@vercel
Copy link

@vercel vercel bot commented on 6f8a961 May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.