Skip to content

Highlight substrings correctly and initial exclusion support with -#131215

Closed
TylerLeonhardt wants to merge 2 commits intomainfrom
TylerLeonhardt/quick-access-improvements
Closed

Highlight substrings correctly and initial exclusion support with -#131215
TylerLeonhardt wants to merge 2 commits intomainfrom
TylerLeonhardt/quick-access-improvements

Conversation

@TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Aug 19, 2021

I’ve been playing around with a few ways to hone in on the files you’re looking for in the cmd+P file search. Taking inspiration from Google & GitHub here’s what quoting and exclusion might look like:

  • wrap a query piece in quotes and that substring must exist "foo"
  • add a dash in front of a query piece and that substring must NOT exist -foo

The results:

quotes-and-minuses minus-vscode-repo

(exclude query pieces can only be used if there’s another piece)
(“pieces” of a query are separated by spaces so asdf bsdf has 2 pieces)

Initially I felt like the exclusion query pieces weren't needed but then I used it more and found it really nice tacking on additional exclusions.

2 commits initially:

  • initial implementation that highlights consecutive maches correctly - this makes it so when searching for "26" the highlight is 2021-9-26 and not 2021-9-26 (if that's hard to read, the 2nd one has highlights on the first 2 instead of the 2 next to the 6)
  • initial support of -foo exclusion query parts

I would recommend looking at the first commit first and then the 2nd.

I haven't fixed up the tests yet but I was hoping to get some feedback from @bpasero before I do that to make sure I'm on the right track generally speaking.

This PR fixes #128923

@TylerLeonhardt TylerLeonhardt added the quick-open Quick-open issues (search, commands) label Aug 19, 2021
@TylerLeonhardt TylerLeonhardt added this to the August 2021 milestone Aug 19, 2021
@TylerLeonhardt TylerLeonhardt requested a review from bpasero August 19, 2021 23:32
@TylerLeonhardt TylerLeonhardt self-assigned this Aug 19, 2021

// Prefer label matches if told so or we have no description
if (preferLabelMatches || !description) {
if ((preferLabelMatches && !query.excludeQuery) || !description) {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is a bit tricky... but the idea is that exclude queries have to happen on the entire path.

Comment on lines +869 to +872
/*
* If a query is wrapped in quotes, the user does not want to
* use fuzzy search for this query.
*/
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
/*
* If a query is wrapped in quotes, the user does not want to
* use fuzzy search for this query.
*/
/*
* If a query starts with a dash and isn't just a dash, the user does not want this
* query to appear in results.
*/

@bpasero
Copy link
Member

bpasero commented Aug 20, 2021

I am wondering how the highlighting is not working properly when using quotes for forcing contiguous matches, isn't that the same that is used for editor history matches, so I would expect we had a bug there already?

I suggest to split the PR up into fixing the highlighting and implementing the support for - so we can discuss both independently.

@bpasero
Copy link
Member

bpasero commented Aug 20, 2021

Oh yeah, I can confirm the highlighting issue, good catch. Reproduces in stable too with entries from editor history:

image

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

High level feedback on the matching fix:

  • rename fuzzy: boolean to allowNonContiguousMatches to make the intent clear (the current wording is confusing)
  • not a big fan of bypassing the scorer matrix for when an exact match is searched, can we not use it but assign a score of 0 within the matrix when we are expecting exact matches and the current match is not contiguous? that way we are not breaking any ranking behaviour we have today already

@TylerLeonhardt
Copy link
Member Author

TylerLeonhardt commented Aug 21, 2021

Ok I've moved the "quote" support to #131292

@bpasero
Copy link
Member

bpasero commented Aug 21, 2021

I am not sure whether we want to push forward on support for - but wouldnt the easiest solution for that just be this:

  • find a leading - and mark the query with a boolean property (similar to how we deal with quotes)
  • run the search normally as before, e.g. each part that is separated by space is a query on its own
  • for any query that is this special one with a - the score is computed as normal but treated specially:
    • a 0 is ignored
    • a score greater 0 results in a score of 0

As such I would think the code changes are relatively small.

@TylerLeonhardt
Copy link
Member Author

I agree, @bpasero. I think it'd be easy to add. Before I go and add - support, I wanna chat with @JacksonKearl and a few others to maybe do some thinking on alignment with our search experiences.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

quick-open Quick-open issues (search, commands)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow exact and excluded matches in fuzzy search

2 participants