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

feat(svelte): Make fuzzy finder matching more reliable#63397

Merged
fkling merged 5 commits into
mainfrom
fkling/srch-139-fuzzy-finder-doesnt-always-match-correctly
Jun 21, 2024
Merged

feat(svelte): Make fuzzy finder matching more reliable#63397
fkling merged 5 commits into
mainfrom
fkling/srch-139-fuzzy-finder-doesnt-always-match-correctly

Conversation

@fkling

@fkling fkling commented Jun 20, 2024

Copy link
Copy Markdown
Contributor

Currently the fuzzy finder filters and ranks results received from the server locally. This was done to improve performance since local filtering is much faster.
However it can introduce inconsistencies (as reported) because the local filtering logic works differently that the one on the server. That means the shown results is depedent on on the local cache, which is not obvious to the user.

This commit removes the client side filtering and ranking and instead relies only on the server for this. This makes things more consistent and predictable, at the expense of being a little slower. However it still feels quite fast to me.

Note that I didn't implement some aspects due to the limitations of the GraphQL-based search API:

  • No match highlighting. Personally I didn't miss is it so far. I don't know if the highlighting actually provides a lot of value.
  • No total result count. It seems since we are adding count:50, the server cannot actually give use an approximate total count. But we should probably still convey somehow that we are limiting results to the top 50.

Because we don't have locally cached data anymore that can be shown immediately I decided to increase the throttle time to prevent the result list flickering in and out when typing with a moderate speed.

This change enables three additional features: 'search all' mode, multi word search and regex search via /.../ literals (just like for normal search queries). This is consistent with our existing search query language (currently regex literals are not syntax highlighted, but we should consider doing that).

Fixes srch-139
Fixes srch-133
Fixes srch-134
Fixes srch-543

sg-sk-resize-.2.mp4

Test plan

Manual testing.

Changelog

  • Add 'search all' tab
  • Support multi-word search
  • Support regular expression patterns
  • Fix matching reliability

Currently the fuzzy finder filters and ranks results received from the
server locally. This was done to improve performance since local
filtering is much faster.
However it can introduce inconsistencies (as reported) because the local
filtering logic works differently that the one on the server. That means
the shown results is depedent on on the local cache, which is not
obvious to the user.

This commit removes the client side filtering and ranking and instead
relies only on the server for this. This makes things more conisten and
predicatable, at the expense of being a little slower. However it still
feels quite fast to me.

Note that I didn't implement some aspects due to the limitations of the
GraphQL-based search API:
- No match highlighting. Personally I didn't miss is it so far. I don't
  know if the highlighting actually provides a lot of value.
- No total result count. It seems since we are adding `count:50`, the
  server cannot actually give use an approximate total count. But we
  should probably still convey somehow that we are limiting results to
  the top 50.
@fkling fkling requested a review from a team June 20, 2024 16:36
@fkling fkling self-assigned this Jun 20, 2024
@cla-bot cla-bot Bot added the cla-signed label Jun 20, 2024
@camdencheek

Copy link
Copy Markdown
Member

Meta: for the changelog entries, should we be specifying that these changes are for the svelte app only?

Comment on lines -169 to -182
let selectedTab = tabs[0]
let selectedOption: number = 0

$: useScope = scope && selectedTab.id !== 'repos'
$: source = selectedTab.source
$: if (open) {
source.next(query)
}
$: if (open) {
dialog?.showModal()
input?.select()
} else {
dialog?.close()
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just moved all of this up to keep variables/constants together.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this was left over from something else. I'll remove this and the related changes.

@fkling

fkling commented Jun 20, 2024

Copy link
Copy Markdown
Contributor Author

@camdencheek I have feat(svelte): at the top.

@fkling fkling changed the title chore(svelte): Make fuzzy finder matching more reliable feat(svelte): Make fuzzy finder matching more reliable Jun 20, 2024

@camdencheek camdencheek left a comment

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.

Looks great!

One thing that feels weird: the All tab being scoped means that I can't switch to other repos in that view. So it's not really a superset of the three other tabs.

Comment on lines +121 to +133
switch (token.type) {
case 'pattern':
if (token.delimited) {
return `${token.delimiter}${token.value}${token.delimiter}`
}
return token.value
case 'filter':
return `"${token.negated ? '-' : ''}${token.field.value}:${escapeQuotes(token.value?.value ?? '')}"`
case 'keyword':
return `"${token.value}"`
default:
return ''
}

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.

Rather than reconstructing the input from parsing it as a normal search query, I wonder if we could do something like zeroOrMore(oneOf<Term>(scanPattern(Literal), scanPattern(Regexp))) (stolen from here)

Feel free to ignore, just thinking it might be nice to reuse some of the underlying machinery rather than undoing the work done by the higher-level machinery.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@camdencheek That's a great idea! Have a look at my recent changes. I'm not happy to have to export a special purpose function form the scanner module but hopefully we can improve that later.
I still need to wrap literals with quotes though so that e.g. repo:foo isn't interpreted in a special way.

@fkling

fkling commented Jun 20, 2024

Copy link
Copy Markdown
Contributor Author

@camdencheek yep, scope switching comes in a separate PR

@fkling

fkling commented Jun 20, 2024

Copy link
Copy Markdown
Contributor Author

@camdencheek or I could of course change the query so that the "scope" isn't applied to repositories. Something like (type:repo OR (<scope> AND (type:path OR type:symbol)) <input>. What do you think?

@camdencheek

Copy link
Copy Markdown
Member

course change the query so that the "scope" isn't applied to repositories

I think that's the behavior I want, but I'm not positive it will be easy to communicate to the user.

@fkling

fkling commented Jun 21, 2024

Copy link
Copy Markdown
Contributor Author

@camdencheek I'd say lets try it and see what feedback we get.

@fkling

fkling commented Jun 21, 2024

Copy link
Copy Markdown
Contributor Author

@camdencheek Actually that doesn't seem to work as I expected. E.g. the query

patterntype:keyword count:50 (type:repo OR (repo:^github\.com/sourcegraph/sourcegraph$ (type:path OR type:symbol)) test

gives me symbol results for repos other than sourcegraph/sourcegraph.

@fkling fkling force-pushed the fkling/srch-139-fuzzy-finder-doesnt-always-match-correctly branch from 8ef996f to 3a5f444 Compare June 21, 2024 19:39
@fkling fkling force-pushed the fkling/srch-139-fuzzy-finder-doesnt-always-match-correctly branch from 9f58614 to 87751a4 Compare June 21, 2024 20:03
@fkling fkling merged commit ce7531f into main Jun 21, 2024
@fkling fkling deleted the fkling/srch-139-fuzzy-finder-doesnt-always-match-correctly branch June 21, 2024 20:23
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.

2 participants