Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed
- Switch autocomplete endpoints to use intsch as primary with intelligentSearchApi as fallback.
- Start testing 10% of the fetchCorrection traffic to intsch and compare the result against the VTEX /IO version.

## [1.80.0] - 2025-09-25

### Changed
Expand Down
2 changes: 1 addition & 1 deletion node/clients/intelligent-search-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class IntelligentSearchApi
})
}

public async correction(params: CorrectionParams) {
public async fetchCorrection(params: CorrectionParams) {
return this.http.get('/correction_search', {
params: { ...params, locale: this.locale },
metric: 'correction',
Expand Down
9 changes: 9 additions & 0 deletions node/clients/intsch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { InstanceOptions, IOContext, JanusClient } from '@vtex/api'
import {
AutocompleteSuggestionsArgs,
AutocompleteSuggestionsResponse,
CorrectionArgs,
CorrectionResponse,
IIntelligentSearchClient,
SearchSuggestionsArgs,
SearchSuggestionsResponse,
Expand Down Expand Up @@ -49,4 +51,11 @@ export class Intsch extends JanusClient implements IIntelligentSearchClient {
metric: 'searchSuggestions-new',
})
}

public fetchCorrection(args: CorrectionArgs): Promise<CorrectionResponse> {
return this.http.get('/api/intelligent-search/v0/correction-search', {
params: { query: args.query, locale: this.locale },
metric: 'correction-new',
})
}
}
14 changes: 14 additions & 0 deletions node/clients/intsch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,25 @@ export type SearchSuggestionsResponse = {
}[]
}

export type CorrectionArgs = {
query: string
}

export type CorrectionResponse = {
correction: {
text: string
highlighted: string
misspelled: boolean
correction: boolean
}
}

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface IIntelligentSearchClient {
fetchAutocompleteSuggestions(
args: AutocompleteSuggestionsArgs
): Promise<AutocompleteSuggestionsResponse>
fetchTopSearches(): Promise<TopSearchesResponse>
fetchSearchSuggestions(args: SearchSuggestionsArgs): Promise<SearchSuggestionsResponse>
fetchCorrection(args: CorrectionArgs): Promise<CorrectionResponse>
}
3 changes: 1 addition & 2 deletions node/mocks/contextFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import parse from 'co-body'

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

Expand Down Expand Up @@ -44,7 +43,7 @@ export function createContext<Ctx = Context>({
},
clients: {
intsch: new MockedIntschClient(intschSettings),
intelligentSearchApi: new MockedIntelligentSearchApiClient(
intelligentSearchApi: new MockedIntschClient(
intelligentSearchApiSettings
),
apps: {
Expand Down
36 changes: 0 additions & 36 deletions node/mocks/intelligent-search-api.ts

This file was deleted.

9 changes: 9 additions & 0 deletions node/mocks/intsch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
AutocompleteSuggestionsResponse,
TopSearchesResponse,
SearchSuggestionsResponse,
CorrectionResponse,
} from '../clients/intsch/types'

export class MockedIntschClient implements IIntelligentSearchClient {
Expand Down Expand Up @@ -30,15 +31,23 @@ export class MockedIntschClient implements IIntelligentSearchClient {
args?.fetchSearchSuggestions ?? null
)
}

if (args?.fetchCorrection instanceof Error) {
this.fetchCorrection.mockRejectedValue(args.fetchCorrection)
} else {
this.fetchCorrection.mockResolvedValue(args?.fetchCorrection ?? null)
}
}

public fetchAutocompleteSuggestions = jest.fn()
public fetchTopSearches = jest.fn()
public fetchSearchSuggestions = jest.fn()
public fetchCorrection = jest.fn()
}

export type IntelligentSearchClientArgs = {
fetchAutocompleteSuggestions?: AutocompleteSuggestionsResponse | Error
fetchTopSearches?: TopSearchesResponse | Error
fetchSearchSuggestions?: SearchSuggestionsResponse | Error
fetchCorrection?: CorrectionResponse | Error
}
10 changes: 3 additions & 7 deletions node/resolvers/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
import {
fetchAutocompleteSuggestions,
fetchTopSearches,
fetchSearchSuggestions
fetchSearchSuggestions,
fetchCorrection,
} from '../../services/autocomplete'
interface ProductIndentifier {
field: 'id' | 'slug' | 'ean' | 'reference' | 'sku'
Expand Down Expand Up @@ -800,12 +801,7 @@ export const queries = {
)
},
correction: (_: any, args: { fullText: string }, ctx: Context) => {
const { intelligentSearchApi } = ctx.clients

return intelligentSearchApi.correction({
query: args.fullText,
...args,
})
return fetchCorrection(ctx, args.fullText)
},
searchSuggestions: (_: any, args: { fullText: string }, ctx: Context) => {
return fetchSearchSuggestions(ctx, args.fullText)
Expand Down
Loading
Loading