Skip to content

Conversation

@david-allison
Copy link
Member

@david-allison david-allison commented Jan 11, 2026

Purpose / Description

In this PR, I implement a draft of the 'Advanced Search' functionality for the Card Browser.

As this is development-only functionality, I would ideally like this merged without productionizing the draft functionality. That being said, please heavily review the intent and the existing code.

I plan to productionize this by adding dialog boxes to the provided options, enabling (for example): selection of valid fields in a drop-down list or autocompleting text view.

The main aim of this functionality is to expose Anki's search syntax to users, without them needing to read the manual.

Although we can use chips for a significant portion of common functionality, Anki's functionality is advanced:

  • Searches can include Regex or wildcards in unusual places:
    • fr*nt:text - search all fields matching the wildcard
    • deck:te*t - a deck search. Not easily representable in the 'deck' chip

So we will provide full text search functionality. Providing explanations, and builders for common functionality will improve discoverability of features, and gives us an opportunity to explain AnkiDroid's features

  • Card Properties
  • States
  • Events

If this screen passes code reviews, it is intended for various 'small' dialogs to be produced. For example: one which will provide the full list of valid fields to select from.

Fixes

Approach

  • Add an advanced mode & button
  • Add a tabbed UI
    • Each tab contains a RecyclerView, each row has a title and an example
    • For now, clicking the row inserts the example into the editText
    • Later, I would like to introduce dialogs for common operations

How Has This Been Tested?

screen-20260111-231015.mp4
  • Tested state restore & don't keep activities

Learning

https://docs.ankiweb.net/searching.html

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison changed the title feat(card-browser): Advanced Search [Dev only] feat(new-card-browser): Advanced Search [Dev only] Jan 11, 2026
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Jan 12, 2026
@david-allison david-allison removed the Needs Author Reply Waiting for a reply from the original author label Jan 16, 2026
Copy link
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

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

Works well. General structure looks great, and the feature idea itself is awesome. Wonderful addition to the app.

Comment on lines 478 to 483
childFragmentManager.findFragmentByTag(tag) ?: factory().also {
childFragmentManager
.beginTransaction()
.add(R.id.search_view_content_container, it, tag)
.commit()
}
Copy link
Member

Choose a reason for hiding this comment

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

hard to read

val options: List<OptionData> = listOf(),
)

val tabData =
Copy link
Member

Choose a reason for hiding this comment

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

can be private. Maybe static as well? I'm not used to have something big like this at the top of the class

Copy link
Member Author

@david-allison david-allison Jan 29, 2026

Choose a reason for hiding this comment

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

I'll leave it for now (as private), it'll likely be reworked as the tabs get more specific functionality

.commit()
}

fun onTemporaryTextChanged(text: String) {
Copy link
Member

Choose a reason for hiding this comment

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

please add docs. I had to think before guessing what temporary text meant

@BrayanDSO BrayanDSO added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Jan 26, 2026
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Jan 26, 2026
@david-allison
Copy link
Member Author

Thanks, I'm going to rewrite this to use a CardBrowserSearchViewModel, which is responsible for the logic while the SearchView is open:

https://github.com/david-allison/Anki-Android/blob/browser-advanced-more/AnkiDroid/src/main/java/com/ichi2/anki/browser/search/CardBrowserSearchViewModel.kt

This adds a wireframe for an advanced search mode in the Card Browser.

Basic operations should can be performed using chips, but advanced operations
 such as `deck:a*` would not be feasible to display.

The advanced mode provides discoverability of many operations which would
 otherwise only be available in the manual

Ignored in the test due to use of `FragmentContainerView`

Issue 18709
[Work in Progress]

This commit adds a basic implementation of Advanced Searches:

An advanced search is just a string

UI:

* A list of categorized options is added in tabs
  * A category would be 'Tags'
  * An option has a title, and an example
  * example: Title: **Notes with no tags**; example: `tags:none`
  * When the option is clicked, the example is appended to the
    search text of the CardBrowserFragment

Strings are hardcoded, there will be a lot of nitpicks on functionality

Code reviews and future commits will replace some options with better
 functionality, this should be done before ossifying the strings via translations

Issue 18709
@david-allison david-allison removed the Needs Author Reply Waiting for a reply from the original author label Jan 29, 2026
It's unexpected to keep old state when closing the
 search view
@david-allison david-allison changed the title feat(new-card-browser): Advanced Search [Dev only] feat(card-browser): Advanced Search [Dev only] Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Second Approval Has one approval, one more approval to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants