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

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open

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
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
@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! 🎖️

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.
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

@@ -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?

matched?: string;
normal?: string;
};

type ModernToken = {
Copy link
Contributor

Choose a reason for hiding this comment

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

NABD, but maybe calling this just Token is fine? as moving forward this is going to be our default token type right?

} 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?

@@ -739,6 +741,7 @@ describe('features/popup-menu - <PopupMenu>', function() {
const props = {
entries: [],
headerEntries: [],
searchFn: searchFn,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
searchFn: searchFn,
searchFn,

@@ -139,6 +139,17 @@ describe('features/searchPad', function() {
} ];
}

if (pattern === 'modern') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should check legacy and treat modern as just the new default. But maybe I miss something fundamental here

@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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Review pending
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants