Skip to content

Commit be89e5f

Browse files
authored
Merge pull request #495 from vtex-apps/feature/rollout-autocomplete-endpoints
Start shifting traffic from VTEX I/O to EKS
2 parents fad7220 + 0212e5d commit be89e5f

File tree

10 files changed

+245
-159
lines changed

10 files changed

+245
-159
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Changed
11+
- Switch autocomplete endpoints to use intsch as primary with intelligentSearchApi as fallback.
12+
- Start testing 10% of the fetchCorrection traffic to intsch and compare the result against the VTEX /IO version.
13+
1014
## [1.80.0] - 2025-09-25
1115

1216
### Changed

node/clients/intelligent-search-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class IntelligentSearchApi
8080
})
8181
}
8282

83-
public async correction(params: CorrectionParams) {
83+
public async fetchCorrection(params: CorrectionParams) {
8484
return this.http.get('/correction_search', {
8585
params: { ...params, locale: this.locale },
8686
metric: 'correction',

node/clients/intsch/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { InstanceOptions, IOContext, JanusClient } from '@vtex/api'
33
import {
44
AutocompleteSuggestionsArgs,
55
AutocompleteSuggestionsResponse,
6+
CorrectionArgs,
7+
CorrectionResponse,
68
IIntelligentSearchClient,
79
SearchSuggestionsArgs,
810
SearchSuggestionsResponse,
@@ -49,4 +51,11 @@ export class Intsch extends JanusClient implements IIntelligentSearchClient {
4951
metric: 'searchSuggestions-new',
5052
})
5153
}
54+
55+
public fetchCorrection(args: CorrectionArgs): Promise<CorrectionResponse> {
56+
return this.http.get('/api/intelligent-search/v0/correction-search', {
57+
params: { query: args.query, locale: this.locale },
58+
metric: 'correction-new',
59+
})
60+
}
5261
}

node/clients/intsch/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,25 @@ export type SearchSuggestionsResponse = {
3535
}[]
3636
}
3737

38+
export type CorrectionArgs = {
39+
query: string
40+
}
41+
42+
export type CorrectionResponse = {
43+
correction: {
44+
text: string
45+
highlighted: string
46+
misspelled: boolean
47+
correction: boolean
48+
}
49+
}
50+
3851
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
3952
export interface IIntelligentSearchClient {
4053
fetchAutocompleteSuggestions(
4154
args: AutocompleteSuggestionsArgs
4255
): Promise<AutocompleteSuggestionsResponse>
4356
fetchTopSearches(): Promise<TopSearchesResponse>
4457
fetchSearchSuggestions(args: SearchSuggestionsArgs): Promise<SearchSuggestionsResponse>
58+
fetchCorrection(args: CorrectionArgs): Promise<CorrectionResponse>
4559
}

node/mocks/contextFactory.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import parse from 'co-body'
22

3-
import { MockedIntelligentSearchApiClient } from './intelligent-search-api'
43
import type { IntelligentSearchClientArgs } from './intsch'
54
import { MockedIntschClient } from './intsch'
65

@@ -44,7 +43,7 @@ export function createContext<Ctx = Context>({
4443
},
4544
clients: {
4645
intsch: new MockedIntschClient(intschSettings),
47-
intelligentSearchApi: new MockedIntelligentSearchApiClient(
46+
intelligentSearchApi: new MockedIntschClient(
4847
intelligentSearchApiSettings
4948
),
5049
apps: {

node/mocks/intelligent-search-api.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

node/mocks/intsch.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
AutocompleteSuggestionsResponse,
44
TopSearchesResponse,
55
SearchSuggestionsResponse,
6+
CorrectionResponse,
67
} from '../clients/intsch/types'
78

89
export class MockedIntschClient implements IIntelligentSearchClient {
@@ -30,15 +31,23 @@ export class MockedIntschClient implements IIntelligentSearchClient {
3031
args?.fetchSearchSuggestions ?? null
3132
)
3233
}
34+
35+
if (args?.fetchCorrection instanceof Error) {
36+
this.fetchCorrection.mockRejectedValue(args.fetchCorrection)
37+
} else {
38+
this.fetchCorrection.mockResolvedValue(args?.fetchCorrection ?? null)
39+
}
3340
}
3441

3542
public fetchAutocompleteSuggestions = jest.fn()
3643
public fetchTopSearches = jest.fn()
3744
public fetchSearchSuggestions = jest.fn()
45+
public fetchCorrection = jest.fn()
3846
}
3947

4048
export type IntelligentSearchClientArgs = {
4149
fetchAutocompleteSuggestions?: AutocompleteSuggestionsResponse | Error
4250
fetchTopSearches?: TopSearchesResponse | Error
4351
fetchSearchSuggestions?: SearchSuggestionsResponse | Error
52+
fetchCorrection?: CorrectionResponse | Error
4453
}

node/resolvers/search/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import {
3636
import {
3737
fetchAutocompleteSuggestions,
3838
fetchTopSearches,
39-
fetchSearchSuggestions
39+
fetchSearchSuggestions,
40+
fetchCorrection,
4041
} from '../../services/autocomplete'
4142
interface ProductIndentifier {
4243
field: 'id' | 'slug' | 'ean' | 'reference' | 'sku'
@@ -800,12 +801,7 @@ export const queries = {
800801
)
801802
},
802803
correction: (_: any, args: { fullText: string }, ctx: Context) => {
803-
const { intelligentSearchApi } = ctx.clients
804-
805-
return intelligentSearchApi.correction({
806-
query: args.fullText,
807-
...args,
808-
})
804+
return fetchCorrection(ctx, args.fullText)
809805
},
810806
searchSuggestions: (_: any, args: { fullText: string }, ctx: Context) => {
811807
return fetchSearchSuggestions(ctx, args.fullText)

0 commit comments

Comments
 (0)