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

Improve search (make fuzzy again and more robust) #932

Merged
merged 12 commits into from
Nov 4, 2024
Merged

Conversation

nikku
Copy link
Member

@nikku nikku commented Sep 23, 2024

Proposed Changes

We found various issues with our existing search, both in terms of robustness and behavior:

This PR solves these issues, while keeping the generally desirable properties:

  • We sort search results semantically, preferring
    • start of word
    • start of term (in word)
    • we sort alphabetically (where items are equal in semantics)

The overall goal is to offer a snappy, robust, and intuitive search behavior, and I'd like to put up to a test if we accomplished that:

capture iz7QYp_optimized

Try it out via

npx @bpmn-io/sr bpmn-io/bpmn-js#use-search -l bpmn-io/diagram-js#fix-search

Checklist

To ensure you provided everything we need to look at your PR:

  • Brief textual description of the changes present
  • Visual demo attached
  • Steps to try out present, i.e. using the @bpmn-io/sr tool
  • Related issue linked via Closes {LINK_TO_ISSUE} or Related to {LINK_TO_ISSUE}

@bpmn-io-tasks bpmn-io-tasks bot added the needs review Review pending label Sep 23, 2024
@nikku nikku requested a review from barmac September 23, 2024 16:27
@nikku
Copy link
Member Author

nikku commented Sep 23, 2024

Additional finding, debugging the implementation:

We do no longer tokenize between spaces, this makes it impossible to match two works, such as this:

image

@nikku

This comment was marked as outdated.

nikku added a commit to camunda/camunda-modeler that referenced this pull request Sep 23, 2024
fix: correct popup menu search on duplicate entries

  Related to bpmn-io/diagram-js#932
nikku added a commit to camunda/camunda-bpmn-js that referenced this pull request Sep 23, 2024
@nikku nikku added the in progress Currently worked on label Sep 25, 2024 — with bpmn-io-tasks
@nikku nikku removed the needs review Review pending label Sep 25, 2024
@barmac barmac marked this pull request as draft September 27, 2024 13:07
@nikku nikku mentioned this pull request Oct 2, 2024
4 tasks
@nikku nikku requested a review from lmbateman October 10, 2024 14:03
@lmbateman
Copy link

Is there a playground where I can try this out? Alternatively, if you need my review, could you please do a quick screen capture to demonstrate the changes? Thanks!

@nikku
Copy link
Member Author

nikku commented Oct 10, 2024

Cf. bpmn-io/bpmn-js#2235 (comment). I'll give you an E2E demo once I'm done with implementing the search, unless you want a demo earlier, to discuss what we do (did), and why.

@nikku nikku added the ready Ready to be worked on label Oct 11, 2024 — with bpmn-io-tasks
@nikku nikku removed the in progress Currently worked on label Oct 11, 2024
@nikku nikku force-pushed the fix-search branch 2 times, most recently from 9b3228e to 1fbd403 Compare October 31, 2024 16:44
@nikku nikku changed the title fix(search): correctly handle duplicate entries Improve search (make fuzzy again and more robust) Oct 31, 2024
@nikku nikku marked this pull request as ready for review October 31, 2024 16:55
@bpmn-io-tasks bpmn-io-tasks bot added needs review Review pending and removed ready Ready to be worked on labels Oct 31, 2024
@nikku nikku force-pushed the fix-search branch 2 times, most recently from 6c502b7 to e1fe8ef Compare October 31, 2024 17:04
@nikku
Copy link
Member Author

nikku commented Oct 31, 2024

I updated this PR to be fuzzy again, and solve all other outstanding issues.

Just now tests revealed that we're not fully fuzzy, actually match too many things, cf. original comment in the popup menu that I subscribe to:

// every word of `search term` should be included in one of the searchable fields

Our current behavior, leading to more search results popping up is:

// at least one word of `search term` should be included in one of the searchable fields

Need to do another round tomorrow.

@nikku
Copy link
Member Author

nikku commented Oct 31, 2024

Now ready to be reviewed.

@nikku nikku force-pushed the fix-search branch 2 times, most recently from a68c85e to 08996a2 Compare November 1, 2024 12:38
@philippfromme philippfromme self-requested a review November 1, 2024 15:08
Copy link
Contributor

@philippfromme philippfromme left a comment

Choose a reason for hiding this comment

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

Great work! 🎖️

Copy link
Contributor

@misiekhardcore misiekhardcore left a comment

Choose a reason for hiding this comment

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

I did some review up to my limited knowledge. Mostly catching some smaller things


results.splice(index, 0, result);
return items.flatMap((item, idx) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

idx seems not to be used anywhere

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed via 5d1d756.

@@ -54,6 +54,7 @@ export default function PopupMenuComponent(props) {
scale,
search,
emptyPlaceholder,
searchFn,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we have some type definition for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also missing here, good catch.

Copy link
Member Author

@nikku nikku Nov 4, 2024

Choose a reason for hiding this comment

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

Fixed via f1a8efe.

lib/features/search-pad/SearchPadProvider.ts Show resolved Hide resolved
} else {
htmlText += escapeHTML(t.normal);
Copy link
Contributor

Choose a reason for hiding this comment

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

so the normal property is not used anymore? What was the purpose of it before?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, that is a bug. 👍

Of course normal is still used, but we did not properly test cover it to date.

Copy link
Member Author

Choose a reason for hiding this comment

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

Bug fix: 32d8f0e

Test coverage added for rendering (different cases): 1fd6df6

test/spec/features/popup-menu/PopupMenuComponentSpec.js Outdated Show resolved Hide resolved
@misiekhardcore
Copy link
Contributor

One general question that crossed my mind when I was playing with it:
Do we want to match partial searches? What I mean
There is an element named User task and user types in the search Ustk so few letters taken from the name in the order of occurance "User task".

@nikku
Copy link
Member Author

nikku commented Nov 4, 2024

Do we want to match partial searches?

This initiative aims to unify search across all places where we use it.

Given the new infrastructure in place (global search utility) integrators can choose what kind of search experience they want.

At the core we want to offer a search that is simple enough, downstream you may plug-in your fuzzy search provider, cf. camunda/camunda-bpmn-js#367.

nikku and others added 12 commits November 4, 2024 17:51
The implementation for comparing entries did not properly account for
entries that are "equal", and whenever they occur it ran into a loop.

The implementation proposed does two things:

* First we simplify the existing logic to be a two step
  filter + sort mechanism
* Second, the search comparison is simple and robust, and handles
  equality well.

This should fix the loop issues we're seeing.

Related to camunda/web-modeler#10940
Reverts 34a65d32abc0c80cc822be13c440c61757ae6376
We ensure that for every entry that is a match we _always_ provide
tokens. This ensures that a user can rely on these tokens being there,
i.e. to render the results.

Related to bpmn-io/bpmn-js#2235
This ensures we properly handle fuzzy results (again),
where parts of the search is matched across different
keys.

This ensures we're not overly strict in filtering things.

Related to bpmn-io/bpmn-js#2235
Tokens returned by `search` are now recognized by the component,
this makes conversion simpler.
Co-authored-by: Michał Konopski <[email protected]>
`search` is now generic, items returned will match the type closure
of searchedEntries (whatever that is).
@nikku
Copy link
Member Author

nikku commented Nov 4, 2024

Squashed the changes, @misiekhardcore ready for another look.

@nikku nikku merged commit 3ab3be3 into develop Nov 4, 2024
12 checks passed
@nikku nikku deleted the fix-search branch November 4, 2024 20:32
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants