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
1 change: 1 addition & 0 deletions static/app/components/searchQueryBuilder/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ export function SearchQueryBuilderProvider({
setDisplayAskSeerFeedback,
replaceRawSearchKeys,
parseQuery,
searchSource,
});

const parsedQuery = useMemo(() => parseQuery(state.query), [parseQuery, state.query]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ describe('replaceFreeTextTokens', () => {
},
}
),
input.rawSearchReplacement
input.rawSearchReplacement,
'test'
);

expect(result?.newQuery).toBe(expected.query);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useCallback, useEffect, useReducer, type Reducer} from 'react';
import * as Sentry from '@sentry/react';
Comment thread
nsdeschenes marked this conversation as resolved.

import {parseFilterValueDate} from 'sentry/components/searchQueryBuilder/tokens/filter/parsers/date/parser';
import {
Expand Down Expand Up @@ -824,6 +825,11 @@ function updateFilterKey(
};
}

function countWords(text: string): number {
const trimmed = text.trim();
return trimmed ? trimmed.split(/\s+/).length : 0;
}

/**
* This function is used to replace free text tokens with the specified
* `replaceRawSearchKeys` prop from `SearchQueryBuilder`. This function also handles
Expand All @@ -839,7 +845,8 @@ function updateFilterKey(
export function replaceFreeTextTokens(
currentQuery: string,
parseQuery: (query: string) => ParseResult | null,
replaceRawSearchKeys: string[]
replaceRawSearchKeys: string[],
searchSource: string
) {
if (
currentQuery.trim().length === 0 ||
Expand Down Expand Up @@ -885,6 +892,28 @@ export function replaceFreeTextTokens(

const value = escapeTagValue(token.text.trim());

// We're doing an experiment here to see if we can detect natural language queries
// and attempt to track them.
if (value.includes(' ')) {
const valueWithNoQuotes = value.slice(1, -1);
const wordCount = countWords(valueWithNoQuotes);

Sentry.logger.info(Sentry.logger.fmt`Found potential natural language query`, {
source: searchSource,
wordCount,
});

Sentry.metrics.count('search_query_builder.potential_natural_language_query', 1, {
attributes: {source: searchSource},
});
Comment thread
nsdeschenes marked this conversation as resolved.

Sentry.metrics.gauge(
'search_query_builder.potential_natural_language_query_word_count',
wordCount,
{attributes: {source: searchSource}}
);
}

// We don't want to break user flows, so if they include an asterisk in their free
// text value, leave it as an `is` filter.
if (value.includes('*')) {
Expand Down Expand Up @@ -923,6 +952,7 @@ function updateFreeTextAndReplaceText(
| UpdateFreeTextActionOnExit
| UpdateFreeTextActionOnCommit,
parseQuery: (query: string) => ParseResult | null,
searchSource: string,
replaceRawSearchKeys?: string[]
): QueryBuilderState {
const newState = updateFreeText(state, action);
Expand All @@ -934,7 +964,8 @@ function updateFreeTextAndReplaceText(
const replacedState = replaceFreeTextTokens(
newState.query,
parseQuery,
replaceRawSearchKeys ?? []
replaceRawSearchKeys ?? [],
searchSource
);

const query = replacedState?.newQuery ? replacedState.newQuery : newState.query;
Expand Down Expand Up @@ -980,19 +1011,21 @@ function updateLogicOperator(
}

export function useQueryBuilderState({
initialQuery,
getFieldDefinition,
disabled,
displayAskSeerFeedback,
getFieldDefinition,
initialQuery,
parseQuery,
setDisplayAskSeerFeedback,
searchSource,
replaceRawSearchKeys,
parseQuery,
}: {
disabled: boolean;
displayAskSeerFeedback: boolean;
getFieldDefinition: FieldDefinitionGetter;
initialQuery: string;
parseQuery: (query: string) => ParseResult | null;
searchSource: string;
setDisplayAskSeerFeedback: (value: boolean) => void;
replaceRawSearchKeys?: string[];
}) {
Expand Down Expand Up @@ -1043,7 +1076,8 @@ export function useQueryBuilderState({
const replacedState = replaceFreeTextTokens(
action.query,
parseQuery,
replaceRawSearchKeys
replaceRawSearchKeys,
searchSource
);

const query = replacedState?.newQuery ? replacedState.newQuery : action.query;
Expand Down Expand Up @@ -1107,6 +1141,7 @@ export function useQueryBuilderState({
state,
action,
parseQuery,
searchSource,
replaceRawSearchKeys
);

Expand Down Expand Up @@ -1166,6 +1201,7 @@ export function useQueryBuilderState({
getFieldDefinition,
parseQuery,
replaceRawSearchKeys,
searchSource,
]
);

Expand Down
Loading