Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

search: support "exact match" pattern using "..."#59057

Merged
stefanhengl merged 2 commits into
mainfrom
sh/kw-search-exact-match
Dec 19, 2023
Merged

search: support "exact match" pattern using "..."#59057
stefanhengl merged 2 commits into
mainfrom
sh/kw-search-exact-match

Conversation

@stefanhengl

@stefanhengl stefanhengl commented Dec 18, 2023

Copy link
Copy Markdown
Member

Relates to #58815

With this change, a quoted pattern, like "foo bar", is interpreted literally IE spaces are interpreted as spaces instead of as logical AND. Quotes that should be matched literally have to be escaped.

Example:

To search for the text foo "bar", where bar is surrounded by quotes, the query is either "foo \"bar\"" or, if we use single quotes, 'foo "bar"'.

Note: This change only affects our keyword search prototype.

Test plan:

  • updated unit test

Relates to #58815

With this change, a quoted pattern, like in `"foo bar"`, is interpreted
literally IE spaces are interpreted as spaces instead of as logical AND.
Quotes, which are part of the pattern have to be escaped.

Example:

searching for the literal `foo "bar"`, where "bar" is surrounded by quotes, the
query is `"foo \"bar\""` (or equivalently `'foo "bar"'`)

Note: This only applies for our keyword search prototype.

Test plan:
- updated unit test
- manual testing
  - tried out various combinations
@stefanhengl stefanhengl marked this pull request as ready for review December 18, 2023 15:16
@sourcegraph-bot

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff d5a6a0a...3728e28.

Notify File(s)
@camdencheek internal/search/query/labels.go
internal/search/query/parser.go
internal/search/query/parser_test.go
internal/search/query/testdata/TestParseNewStandard/literal_quotes_1._Double_quotes_within_single_quotes.golden
internal/search/query/testdata/TestParseNewStandard/literal_quotes_2._Double_quotes_within_double_quotes.golden
internal/search/query/testdata/TestParseNewStandard/quoted_patterns_are_interpreted_literally.golden
internal/search/query/testdata/TestParseNewStandard/quotes_which_are_part_of_the_pattern_have_to_be_escaped.golden
@jtibshirani internal/search/query/labels.go
internal/search/query/parser.go
internal/search/query/parser_test.go
internal/search/query/testdata/TestParseNewStandard/literal_quotes_1._Double_quotes_within_single_quotes.golden
internal/search/query/testdata/TestParseNewStandard/literal_quotes_2._Double_quotes_within_double_quotes.golden
internal/search/query/testdata/TestParseNewStandard/quoted_patterns_are_interpreted_literally.golden
internal/search/query/testdata/TestParseNewStandard/quotes_which_are_part_of_the_pattern_have_to_be_escaped.golden
@keegancsmith internal/search/query/labels.go
internal/search/query/parser.go
internal/search/query/parser_test.go
internal/search/query/testdata/TestParseNewStandard/literal_quotes_1._Double_quotes_within_single_quotes.golden
internal/search/query/testdata/TestParseNewStandard/literal_quotes_2._Double_quotes_within_double_quotes.golden
internal/search/query/testdata/TestParseNewStandard/quoted_patterns_are_interpreted_literally.golden
internal/search/query/testdata/TestParseNewStandard/quotes_which_are_part_of_the_pattern_have_to_be_escaped.golden

@jtibshirani jtibshirani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change turned out really cleanly!

I'm not totally convinced we should be supporting the single quote version. I haven't seen this in any other search query language ... I've only seen it in the context of string syntax in certain programming languages. I don't feel strongly though. What do you think?

Also adding @camdencheek as a reviewer so he can weigh in on these types of changes.

// than canonical form (r: instead of repo:)
IsAlias
Standard
QuotesAsLiterals

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually added to any nodes? In all the added tests, I don't see this show up anywhere. It seems like this is being used as an option rather than a label, which is a little confusing to me. That said...seems like we might be doing that already with Standard 😬

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is being used as an option rather than a label, which is a little confusing to me. That said...seems like we might be doing that already with Standard

You are correct, it's used as an option, not as a label. I modelled it after Standard. I can see that this might be confusing. Given that Standard follows the same approach and given that this change here was straightforward by treating the label as option, I wonder whether it is worth it to introduce dedicated parser options to distinguish between the two concepts.

@camdencheek

Copy link
Copy Markdown
Member

No strong opinion personally on single/double quotes. It is pretty nice to be able to just switch to the other type of quote if the literal I'm looking for contains quotes.

@stefanhengl

stefanhengl commented Dec 19, 2023

Copy link
Copy Markdown
Member Author

I think the single quotes are a nice touch, but not essential. I usually try if single quotes work if escaping double quotes gets out of hand. If you don't mind, I suggest we leave it in for now. We still have some time to get a feeling for this.

@stefanhengl stefanhengl merged commit f883d66 into main Dec 19, 2023
@stefanhengl stefanhengl deleted the sh/kw-search-exact-match branch December 19, 2023 09:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants