mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:51:57 +00:00
search: log lucky search events (#39329)
This commit is contained in:
parent
98c48b28cf
commit
8a5ec31d24
@ -41,7 +41,7 @@ import { GettingStartedTour } from '../../tour/GettingStartedTour'
|
||||
import { SearchUserNeedsCodeHost } from '../../user/settings/codeHosts/OrgUserNeedsCodeHost'
|
||||
import { submitSearch } from '../helpers'
|
||||
import { DidYouMean } from '../suggestion/DidYouMean'
|
||||
import { LuckySearch } from '../suggestion/LuckySearch'
|
||||
import { LuckySearch, luckySearchEvent } from '../suggestion/LuckySearch'
|
||||
|
||||
import { SearchAlert } from './SearchAlert'
|
||||
import { useCachedSearchResults } from './SearchResultsCacheProvider'
|
||||
@ -167,6 +167,19 @@ export const StreamingSearchResults: React.FunctionComponent<
|
||||
}
|
||||
}, [results, telemetryService])
|
||||
|
||||
// Log lucky search events
|
||||
useEffect(() => {
|
||||
if (results?.alert?.kind === 'lucky-search-queries' && results?.alert?.title && results.alert.proposedQueries) {
|
||||
const events = luckySearchEvent(
|
||||
results.alert.title,
|
||||
results.alert.proposedQueries.map(entry => entry.description || '')
|
||||
)
|
||||
for (const event of events) {
|
||||
telemetryService.log(event)
|
||||
}
|
||||
}
|
||||
}, [results, telemetryService])
|
||||
|
||||
useNotepad(
|
||||
useMemo(
|
||||
() =>
|
||||
|
||||
@ -49,3 +49,28 @@ export const LuckySearch: React.FunctionComponent<React.PropsWithChildren<LuckyS
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
|
||||
export const luckySearchEvent = (alertTitle: string, descriptions: string[]): string[] => {
|
||||
const rules = descriptions.map(entry => {
|
||||
if (entry.match(/patterns as regular expressions/)) {
|
||||
return 'Regexp'
|
||||
}
|
||||
if (entry.match(/unquote patterns/)) {
|
||||
return 'Unquote'
|
||||
}
|
||||
if (entry.match(/AND patterns together/)) {
|
||||
return 'And'
|
||||
}
|
||||
return 'Other'
|
||||
})
|
||||
|
||||
const prefix = alertTitle.match(/No results for original query/)
|
||||
? 'SearchResultsAutoPure'
|
||||
: 'SearchResultsAutoAdded'
|
||||
|
||||
const events = []
|
||||
for (const rule of rules) {
|
||||
events.push(`${prefix}${rule}`)
|
||||
}
|
||||
return events
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user