Skip to content

Conversation

@Rylern
Copy link
Collaborator

@Rylern Rylern commented Mar 14, 2025

Improve the Javadoc search. I made a few choices that can be discussed:

  • The search doesn't show any suggestions of package, module, variable, exception, annotation, or element.
  • The search show suggestions in that order: class, interface, enum, constructor, static method, method.
  • The filter has been changed:
    • If the suggestion is a class or an interface, its name is something like some.package.Class. The filter only looks at Class.
    • If the suggestion is an enum, its name is something like some.package.Class.Enum or Class.Enum.variable. The filter looks at Class.Enum or Enum.variable.
    • If the suggestion is a constructor, static method, or method, its name is something like Class.Class(Parameter) for constructors or Class.function(Parameter) for functions. The filter looks at Class or function.

I also did a bit of refactoring to improve error handling.

Copy link
Member

@petebankhead petebankhead left a comment

Choose a reason for hiding this comment

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

I like this better. I'm still having some trouble: for example, if I search for ROI then the ROI interface I expect doesn't appear anywhere.

This is partly because AutoCompleteTextFieldEntry.MAX_ENTRIES is quite low. Is there any reason this can't be increased, at least to 100?

Something that could help more is to specify a comparator based on the text input. For example, this should cause exact matches to bubble up to the top - and then preferentially shows matches that start with the same text. This still means that ImageJ's Roi comes on top when I search ROI (interfaces are lower), but that's still preferable to EllipseRoi.

    private void setUpListeners() {
        textProperty().addListener((p, o, n) -> {
            String enteredText = getText();

            if (enteredText == null || enteredText.isEmpty()) {
                entriesPopup.hide();
            } else {
                String loweredCaseEnteredText = enteredText.toLowerCase();

                Comparator<AutoCompleteTextFieldEntry> comparator =
                        Comparator.comparing((AutoCompleteTextFieldEntry e) -> e.getSearchableText().toLowerCase().equals(loweredCaseEnteredText) ? -1 : 1)
                                       .thenComparing(e -> e.getSearchableText().toLowerCase().startsWith(loweredCaseEnteredText) ? -1 : 1)
                                        .thenComparing(AutoCompleteTextFieldEntry::compareTo);
                populatePopup(
                        suggestions.stream()
                                .filter(entry -> entry.getSearchableText().toLowerCase().contains(loweredCaseEnteredText))
                                .sorted(comparator)
                                .limit(MAX_ENTRIES)
                                .toList(),
                        enteredText
                );
            }
        });

        focusedProperty().addListener((p, o, n) -> entriesPopup.hide());
    }

Apache Commons Text has similarity and distance functions that might be useful, but I'm not sure - I think a few simple adjustments to the Comparator like this could be enough.

A few other things:

  • Constructors include class names repeated. If I search for ImageData, I see ImageData.ImageData(ImageServer<T>).
    • This example also shows a problem with my Comparator preferring exact equals... typing ImageDat shows me the class ImageData first, but typing ImageData exactly shows me the constructor first.
  • I find it unexpected that selecting an item that I searched for results in the search text field showing the full item, not what I had previously typed

Copy link
Contributor

@alanocallaghan alanocallaghan left a comment

Choose a reason for hiding this comment

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

I can't build at the moment because of maven 503s but it looks good

@Rylern
Copy link
Collaborator Author

Rylern commented Mar 17, 2025

All comments have been addressed

Copy link
Member

@petebankhead petebankhead left a comment

Choose a reason for hiding this comment

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

Thanks, approved now - from my side this can be merged.

@Rylern Rylern merged commit 2523c39 into main Mar 17, 2025
1 check passed
@Rylern Rylern deleted the improved-search branch March 17, 2025 11:06
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