Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlight matched fields in search results #8651

Merged

Conversation

joshuaeilers
Copy link
Contributor

@joshuaeilers joshuaeilers commented Aug 16, 2023

Substantial overhaul to the visual search highlighting approach in datahub.

⚠️ What this PR does NOT do:

  • Does NOT highlight where in the text based on elastic search, it does fuzzy highlights by simple substring
  • Does NOT include glossary term search, but does setup highlighting once that is implemented

Changes

  • Client-side mapping of use case to entity-specific field names
  • A new SearchResultContext which always passes the search result down from the EntityRegistry
  • Entities loaded on MatchedField (thank you to Chris)
  • A base set of highlighting components that accept a prop for overrides, only chart/dashboard need for now
  • Removed some no longer used files
  • Some search code moved under the search directory which felt more appropriate
  • New colors added to the theme
Screenshot 2023-08-17 at 3 05 59 PM

@github-actions github-actions bot added the product PR or Issue related to the DataHub UI/UX label Aug 16, 2023
@@ -0,0 +1,40 @@
import React from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is super confusing. I just ported it from the snippet component that was here.

Copy link
Collaborator

@chriscollins3456 chriscollins3456 left a comment

Choose a reason for hiding this comment

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

this is looking real solid! i love how much cleaner matched code is now and love the new context.

I have a few minor suggestions and one question/concern about highlighting text without any matching substrings and a situation that it looks off in search results

@@ -665,6 +665,11 @@ type MatchedField {
Value of the field that matched
"""
value: String!

"""
Entity if the value was an urn
Copy link
Collaborator

Choose a reason for hiding this comment

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

"was" -> "is"

matchedFields={result.matchedFields}
inputFields={data.inputFields}
<MatchedFieldList
customFieldRenderer={(matchedField) => chartMatchedFieldRenderer(matchedField, data)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this is being used for chats/dashboards maybe a different name could be used? something like matchedInputFieldRenderer since these two entities has inputFields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sounds good. I'll adjust the dataset one as well.

return matchedField ? (
<Typography.Text>
Matches {FIELDS_TO_HIGHLIGHT.get(matchedField.name)} <b>{matchedField.value}</b>{' '}
{isMatchingDashboard && 'on a contained Chart'}
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to drop the "on a contained Chart" piece?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I'll add a prop for that.

datahub-web-react/src/app/search/context/utils.ts Outdated Show resolved Hide resolved
if (customRenderedField) return <b>{customRenderedField}</b>;
if (field.value.includes('urn:li:tag') && !field.entity) return <></>;
if (field.entity) return <>{entityRegistry.getDisplayName(field.entity.type, field.entity)}</>;
if (field.name.toLowerCase().includes('description') && query) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think there's at least one or two other places where you're checking if something includes "description" -> could be a constant!

Comment on lines +24 to +32
export const SearchResultProvider = ({ children, searchResult }: Props) => {
const value = useMemo(
() => ({
searchResult,
}),
[searchResult],
);
return <SearchResultContext.Provider value={value}>{children}</SearchResultContext.Provider>;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

love it

const customRenderedField = customFieldRenderer?.(field);
if (customRenderedField) return <b>{customRenderedField}</b>;
if (field.value.includes('urn:li:tag') && !field.entity) return <></>;
if (field.entity) return <>{entityRegistry.getDisplayName(field.entity.type, field.entity)}</>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you know all the types of entities that could be in this field? obviously tag and glossary term and the first that come to mind. Just want to make sure we don't get to a situation where we pass in an entity not configured in our frontend EntityRegistry that causes an error to be thrown and a white screen of death

Comment on lines 25 to 26
const hasSubstring = hasMatchedField && !!normalizedSearchQuery && normalizedText.includes(normalizedSearchQuery);
const pattern = enableFullHighlight ? HIGHLIGHT_ALL_PATTERN : undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

i'm a little confused by the full highlight situation - why do we want to highlight the full text if it doesn't match anything in the search query? after pulling down I'm seeing situations like this where my search query is long_tail and ADOPTIONS is being highlighted (but I believe these results are showing up because long_tail matches their container's name)
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't seem to have this same data to repro this, will ping ya.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main reason for highlighting all is for situation where you search for baz 2 we would still end up highlighting 'Baz Chart 2' since it has a title match. Otherwise, we'll end up not highlighting it. The idea here was to trust the backend, if it's saying we matched the name, let's highlight the name to indicate as such.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed qualifiedName from fields we highlight since we only use that for container names and the solve would be complex.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nice this solved my issue i was seeing

Comment on lines +835 to +839
entity {
urn
type
...entityDisplayNameFields
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

Copy link
Collaborator

@chriscollins3456 chriscollins3456 left a comment

Choose a reason for hiding this comment

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

nice stuff man! thanks for knocking a rather complicated feature out so quick

"""
Whether a search result should highlight the name/description if it was matched on those fields.
"""
enableNameHighlight: Boolean
Copy link
Collaborator

Choose a reason for hiding this comment

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

thank you for adding this!

@joshuaeilers joshuaeilers merged commit a78e72c into datahub-project:master Aug 24, 2023
41 of 43 checks passed
@joshuaeilers joshuaeilers deleted the je--highilght-matched-fields branch August 24, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product PR or Issue related to the DataHub UI/UX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants