@@ -32,6 +32,7 @@ import { CodePreviewPanel } from "./codePreviewPanel";
3232import { FilterPanel } from "./filterPanel" ;
3333import { useFilteredMatches } from "./filterPanel/useFilterMatches" ;
3434import { SearchResultsPanel , SearchResultsPanelHandle } from "./searchResultsPanel" ;
35+ import useCaptureEvent from "@/hooks/useCaptureEvent" ;
3536
3637interface SearchResultsPageProps {
3738 searchQuery : string ;
@@ -50,6 +51,7 @@ export const SearchResultsPage = ({
5051 const { setSearchHistory } = useSearchHistory ( ) ;
5152 const domain = useDomain ( ) ;
5253 const { toast } = useToast ( ) ;
54+ const captureEvent = useCaptureEvent ( ) ;
5355
5456 // Encodes the number of matches to return in the search response.
5557 const _maxMatchCount = parseInt ( useNonEmptyQueryParam ( SearchQueryParams . matches ) ?? `${ defaultMaxMatchCount } ` ) ;
@@ -59,7 +61,8 @@ export const SearchResultsPage = ({
5961 error,
6062 files,
6163 repoInfo,
62- durationMs,
64+ timeToSearchCompletionMs,
65+ timeToFirstSearchResultMs,
6366 isStreaming,
6467 numMatches,
6568 isExhaustive,
@@ -98,40 +101,52 @@ export const SearchResultsPage = ({
98101 ] )
99102 } , [ searchQuery , setSearchHistory ] ) ;
100103
101- // @todo : capture search stats on completion.
102- // useEffect(() => {
103- // if (!searchResponse) {
104- // return;
105- // }
104+ useEffect ( ( ) => {
105+ if ( isStreaming || ! stats ) {
106+ return ;
107+ }
106108
107- // const fileLanguages = searchResponse. files? .map(file => file.language) || [];
109+ const fileLanguages = files . map ( file => file . language ) || [ ] ;
108110
109- // captureEvent("search_finished", {
110- // durationMs: searchResponse.totalClientSearchDurationMs,
111- // fileCount: searchResponse.stats.fileCount,
112- // matchCount: searchResponse.stats.totalMatchCount,
113- // actualMatchCount: searchResponse.stats.actualMatchCount,
114- // filesSkipped: searchResponse.stats.filesSkipped,
115- // contentBytesLoaded: searchResponse.stats.contentBytesLoaded,
116- // indexBytesLoaded: searchResponse.stats.indexBytesLoaded,
117- // crashes: searchResponse.stats.crashes,
118- // shardFilesConsidered: searchResponse.stats.shardFilesConsidered,
119- // filesConsidered: searchResponse.stats.filesConsidered,
120- // filesLoaded: searchResponse.stats.filesLoaded,
121- // shardsScanned: searchResponse.stats.shardsScanned,
122- // shardsSkipped: searchResponse.stats.shardsSkipped,
123- // shardsSkippedFilter: searchResponse.stats.shardsSkippedFilter,
124- // ngramMatches: searchResponse.stats.ngramMatches,
125- // ngramLookups: searchResponse.stats.ngramLookups,
126- // wait: searchResponse.stats.wait,
127- // matchTreeConstruction: searchResponse.stats.matchTreeConstruction,
128- // matchTreeSearch: searchResponse.stats.matchTreeSearch,
129- // regexpsConsidered: searchResponse.stats.regexpsConsidered,
130- // flushReason: searchResponse.stats.flushReason,
131- // fileLanguages,
132- // });
133- // }, [captureEvent, searchQuery, searchResponse]);
111+ console . debug ( 'timeToFirstSearchResultMs:' , timeToFirstSearchResultMs ) ;
112+ console . debug ( 'timeToSearchCompletionMs:' , timeToSearchCompletionMs ) ;
134113
114+ captureEvent ( "search_finished" , {
115+ durationMs : timeToSearchCompletionMs ,
116+ timeToSearchCompletionMs,
117+ timeToFirstSearchResultMs,
118+ fileCount : stats . fileCount ,
119+ matchCount : stats . totalMatchCount ,
120+ actualMatchCount : stats . actualMatchCount ,
121+ filesSkipped : stats . filesSkipped ,
122+ contentBytesLoaded : stats . contentBytesLoaded ,
123+ indexBytesLoaded : stats . indexBytesLoaded ,
124+ crashes : stats . crashes ,
125+ shardFilesConsidered : stats . shardFilesConsidered ,
126+ filesConsidered : stats . filesConsidered ,
127+ filesLoaded : stats . filesLoaded ,
128+ shardsScanned : stats . shardsScanned ,
129+ shardsSkipped : stats . shardsSkipped ,
130+ shardsSkippedFilter : stats . shardsSkippedFilter ,
131+ ngramMatches : stats . ngramMatches ,
132+ ngramLookups : stats . ngramLookups ,
133+ wait : stats . wait ,
134+ matchTreeConstruction : stats . matchTreeConstruction ,
135+ matchTreeSearch : stats . matchTreeSearch ,
136+ regexpsConsidered : stats . regexpsConsidered ,
137+ flushReason : stats . flushReason ,
138+ fileLanguages,
139+ isSearchExhaustive : isExhaustive ,
140+ } ) ;
141+ } , [
142+ captureEvent ,
143+ files ,
144+ isStreaming ,
145+ isExhaustive ,
146+ stats ,
147+ timeToSearchCompletionMs ,
148+ timeToFirstSearchResultMs ,
149+ ] ) ;
135150
136151 const onLoadMoreResults = useCallback ( ( ) => {
137152 const url = createPathWithQueryParams ( `/${ domain } /search` ,
@@ -170,7 +185,7 @@ export const SearchResultsPage = ({
170185 onLoadMoreResults = { onLoadMoreResults }
171186 numMatches = { numMatches }
172187 repoInfo = { repoInfo }
173- searchDurationMs = { durationMs }
188+ searchDurationMs = { timeToSearchCompletionMs }
174189 isStreaming = { isStreaming }
175190 searchStats = { stats }
176191 isMoreResultsButtonVisible = { ! isExhaustive }
0 commit comments